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

解决方案 »

  1.   

    先确认你你访问的窗体和label是你要的吗
      

  2.   

    下面是XE2的代码,你自己比对下是哪的问题
    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.