Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Thread Class and Form Class visibility?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Dec 16, 2016 4:01 AM Last Post By: Toby Dobbs
Toby Dobbs

Posts: 77
Registered: 9/24/16
Thread Class and Form Class visibility?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 4:00 AM
Hi,

For some reason my thread class doesn't seem to be able to see components within my form class. Why is this and what should I do differently?

procedure TMyThread.ScanToPlot;
begin
  TCustomForm1.Button1.Click;
end;
 
procedure TMyThread.Execute;
begin
  NameThreadForDebugging('Toby''s thread.');
  Synchronize(ScanToPlot);
end;
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Thread Class and Form Class visibility?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 10:11 AM   in response to: Toby Dobbs in response to: Toby Dobbs
Toby Dobbs wrote:

Hi,

For some reason my thread class doesn't seem to be able to see
components within my form class. Why is this and what should I do
differently?

You need to use the form variable, not the form class. The variable
(for autocreated forms) contains the reference of the form instance.


--
Peter Below
TeamB

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Thread Class and Form Class visibility?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 12:38 PM   in response to: Peter Below in response to: Peter Below
Peter wrote:

You need to use the form variable, not the form class. The
variable (for autocreated forms) contains the reference of the form
instance.

Like this:

procedure TMyThread.ScanToPlot;
begin
  Form1.Button1.Click;
end;


I would take it a step further by moving ScanToPlot() into the Form class:

procedure TForm1.ScanToPlot;
begin
  Button1.Click;
end;
 
procedure TMyThread.Execute;
begin
  NameThreadForDebugging('Toby''s thread.');
  Synchronize(Form1.ScanToPlot);
end;


Or, if that is ALL that ScanToPlot() does, then just get rid of it altogether:

procedure TMyThread.Execute;
begin
  NameThreadForDebugging('Toby''s thread.');
  Synchronize(Form1.Button1.Click);
end;


Or just call the OnClick event handler directly:

procedure TMyThread.Execute;
begin
  NameThreadForDebugging('Toby''s thread.');
  Synchronize(Form1.Button1Click);
end;


--
Remy Lebeau (TeamB)
Toby Dobbs

Posts: 77
Registered: 9/24/16
Re: Thread Class and Form Class visibility?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2016 4:01 AM   in response to: Toby Dobbs in response to: Toby Dobbs
Thanks, rather an oversight.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02