首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

DELPHI 线程访问VCL 不能取得字符的有关问题

2012-08-02 
DELPHI 线程访问VCL 不能取得字符的问题现在有LBL1标签控件我在线程中str:form1.lbl1.Caption 获取到的字

DELPHI 线程访问VCL 不能取得字符的问题
现在有LBL1标签控件
我在线程中str:=form1.lbl1.Caption 获取到的字符为空 
但在正常的BUTTON下 却能正常获取
谁能告诉我在线程下要怎么获取啊
不是说线程中 只要不写入VCL都是安全的么

[解决办法]
下面是XE2的代码,你自己比对下是哪的问题

Delphi(Pascal) code
unit Unit1;interfaceuses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,  Vcl.StdCtrls;type  TForm1 = class(TForm)    Button1: TButton;    lbl1: TLabel;    procedure Button1Click(Sender: TObject);  end;  TMyThread = class(TThread)  protected    procedure Execute; override;  end;var  Form1: TForm1;implementation{$R *.dfm}{ TMyThread }procedure TMyThread.Execute;begin  FreeOnTerminate := True;  Synchronize(procedure  begin    Form1.Caption := Form1.lbl1.Caption;  end);end;procedure TForm1.Button1Click(Sender: TObject);begin  TMyThread.Create;end;end. 

热点排行