通过发消息,来刷新界面的信息, 不失为一种好方法
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
相关文章推荐
- 通过消息拦截达到在Delphi控件中屏蔽原有事件处理的一种方法
- 一种通过xmpp实现离线消息推送的方法及系统
- cocos2d-x3.3通过消息刷新界面
- UI线程中需要通过网络请求拿到数据再刷新界面的不阻塞的方法
- 一种通过xmpp实现离线消息推送的方法及系统
- 一个流行且实用的JS表单验证提示,演示了怎么自定义错误信息的显示方式,同时通过写FormValid.showError类方法来实现错误显示方式自定义: errMsg 是一个错误消息的数组,这样方便自定
- log4j通过配置文件配置即,即可完成系统报错想向指定邮箱发送提醒消息,网上的很多方法都又问题
- Android中通过样式来去除app的头及界面全屏(备忘)的实现方法
- C#后台线程工作时更新界面的一种处理方法
- 通过CMWAP下载大文件一种实现方法
- 通过中间人攻击的方法拦截传输在https上的加密信息
- 利用JNI方法,通过WMI获取本地硬件信息(主板型号,硬盘序列号,CPU参数等)
- MFC界面刷新方法总结
- 一种粗略的普通摄像头深度信息提取方法
- Java中通过反射获取类的信息(方法名,参数,构造函数等)
- 刷新页面后,数据保留在原页面方法(session信息共享,ajax局部刷新)
- jquery mobile界面数据刷新的实现方法
- 亲身体会:一种需要取得子类详细信息的情况(五种方法)
- java通过反射+javassist获得方法所有信息(返回值、方法名、参数类型列表、参数列表)
- Objective-C中一种消息处理方法performSelector