Advertisement

05.14.2008 at 11:32AM PDT, ID: 23402607
[x]
Attachment Details

TThread.Terminated becomes invisible when TThread class is in separate Unit

Asked by SteveFarndon2000 in Delphi Programming, Delphi Programming Language

Tags: Delphi, TThread

Hello All,

There must be a simple solution to this but I can't see it.

If you declare a TThread class in the same module as your TForm code then the compiler recognises its protected  "Terminated" property.
If you move the TThread class to a separate .pas module then Delphi complains with "Cannot access protected symbol TThread.Terminated".

Why?

I can get around the problem by simply declaring a public property called "Terminated" in the second case (see the commented-out line of code in the example) but this, I suspect, will have negative side-effects somewhere down the line.
So how do I avoid  a "get around"? Is there some compiler switch that I'm missing?

Thanks in advance.

Stephen

(Environment is Delphi2006, WinXP SP2 }Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,unit2;
type
  TAt2 = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;
 
  TTextA = class(TObject)
  t1 : TAt;   // <-- from unit2.pas
  t2  : TAt2; // <-- locally declared TThread class
  constructor create();
  destructor destroy();
  procedure checkThread();
  end;
 
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
constructor TTextA.create();
begin
inherited;
end;
 
destructor TTextA.destroy();
begin
end;
 
procedure TTextA.checkThread;
begin
if (t2.terminated) then exit;
if (t1.terminated) then exit;
end;
 
procedure TAt2.Execute;
begin
  { Place thread code here }
end;
 
end.
 
//------------------------------------------------------------------------------
..AND THE SECOND MODULE...
unit Unit2;
interface
uses
  Classes;
 
type
  TAt = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  public
   //property Terminated;  <-- uncomment this an compiles OK
  end;
 
implementation
 
procedure TAt.Execute;
begin
  { Place thread code here }
end;
 
end.
 
Loading Advertisement...
 
[+][-]05.14.2008 at 11:35AM PDT, ID: 21567237

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 11:43AM PDT, ID: 21567314

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.14.2008 at 11:43AM PDT, ID: 21567316

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 11:08PM PDT, ID: 21570960

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Delphi Programming, Delphi Programming Language
Tags: Delphi, TThread
Sign Up Now!
Solution Provided By: Geert_Gruwez
Participating Experts: 3
Solution Grade: B
 
 
[+][-]05.15.2008 at 02:26AM PDT, ID: 21571755

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 03:15AM PDT, ID: 21571978

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 03:32AM PDT, ID: 21572066

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 04:13AM PDT, ID: 21572297

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 05:26AM PDT, ID: 21572708

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 11:10AM PDT, ID: 21576549

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 01:14PM PDT, ID: 21577559

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628