您的位置:首页 > 其它

通过发消息,来刷新界面的信息, 不失为一种好方法

2016-12-14 13:33 411 查看
代码:

unit U_DownLoadApp;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls,

IdHTTP;

const

WM_WebUpdate = WM_USER + 1000;

type

TDownLoadAppThread = class(TThread)

private

FRunType: Integer;
FMainForm: TForm;

procedure Procedure0;

procedure Procedure1;

protected

procedure Execute; override;

public

property RunType: Integer read FRunType write FRunType;

property MainForm: TForm read FMainForm write FMainForm;
end;

implementation

{ TDownLoadAppThread }

procedure TDownLoadAppThread.Execute;

begin

inherited;

case FRunType of

0: Procedure0;

1: Procedure1;

end;

end;

procedure TDownLoadAppThread.Procedure0;

var

IDHttp: TIdHTTP;

sWeb: string;

begin

IDHttp := TIdHTTP.Create(nil);

try

sWeb := IDHttp.Get('http://down.360safe.com/se/360se8.1.1.240.exe');

SendMessage(FMainForm.Handle, WM_WebUpdate, Integer(PChar(sWeb)), 0);

finally

IDHttp.Free;

end;

end;

procedure TDownLoadAppThread.Procedure1;

begin

//类别1执行代码

end;

end.


代码

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls;

type
TMainForm = class(TForm)
IdHTTP1: TIdHTTP;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure WMWebUpdate(var AMessage: TMessage);
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

uses U_DownLoadApp;

{$R *.dfm}

procedure TMainForm.WMWebUpdate(var AMessage: TMessage);

var

pWeb: PChar;

begin

pWeb := PChar(AMessage.WParam);

Memo1.Lines.Add(pWeb);

end;

procedure TMainForm.Button1Click(Sender: TObject);
var

MyThread0, MyThread1: TDownLoadAppThread;

begin

MyThread0 := TDownLoadAppThread.Create(True);

MyThread0.FreeOnTerminate := True;

MyThread0.RunType := 0;

MyThread0.Resume;

//
//  MyThread1 := TDownLoadAppThread.Create(True);
//
//  MyThread1.FreeOnTerminate := True;
//
//  MyThread1.RunType := 1;
//
//  MyThread1.Resume;

end;

end.


object MainForm: TMainForm
Left = 415
Top = 231
Width = 746
Height = 465
Caption = 'MainForm'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Memo1: TMemo
Left = 160
Top = 16
Width = 537
Height = 385
Lines.Strings = (
'Memo1')
ScrollBars = ssBoth
TabOrder = 0
end
object Button1: TButton
Left = 40
Top = 152
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object IdHTTP1: TIdHTTP
MaxLineAction = maException
ReadTimeout = 0
AllowCookies = True
ProxyParams.BasicAuthentication = False
ProxyParams.ProxyPort = 0
Request.ContentLength = -1
Request.ContentRangeEnd = 0
Request.ContentRangeStart = 0
Request.ContentType = 'text/html'
Request.Accept = 'text/html, */*'
Request.BasicAuthentication = False
Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
HTTPOptions = [hoForceEncodeParams]
Left = 104
Top = 48
end
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐