problem with  threads

balangate
balangate used Ask the Experts™
on
I can't use findcomponent in a threads

someone help me !!!!!!!!!!!

thanks a lot.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Give some sample code.
type

  TCheckThread = class(TThread)
  public
    procedure Execute;override;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TCheckThread.Execute;
var
  AComp: TComponent;
begin
  AComp := Form1.FindComponent('Label1');
  if AComp <> nil then
    if (AComp is TLabel) then
      (AComp as TLabel).Caption := 'OK';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  AThread : TCheckThread;
begin
  AThread := TCheckThread.create(true); // create suspended
  with AThread do begin
    FreeOnTerminate := true;
    Resume; // and let the thread run...
  end;
end;

end.

Commented:
You must synchronize VCL-calls in your Execute Method.

Place your stuff in a separate Method liek "MyMethod" and call from Execute these Method with Synchronize(MyMethod).

Author

Commented:
thanks a lot :)
You are welcome. Why 'B' grade then?

Regards, Geo

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial