|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by bryan7 in Delphi Programming, Free Pascal
Hello,
I'm wondering about the best way to handle this:
I have 2 classes. I create the 1st class, which creates the 2nd class in the Constructor; the 2nd class must access the 1st class in its constructor, but it can't because 1st class is not assigned yet (proven in the code). How would you approach this? I tried AfterConstruction, which didn't work either. I could use a timer or sending a msg to call the 2nd class constructor after the 1st one has finished, but I'd rather use a better way, and within my 1st class (not sending a msg).
What would you do?
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:
|
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type class1 = Class(TObject)
public
Constructor Create;
Destructor Destroy;
End;
type class2 = Class(TObject)
public
Constructor Create;
Destructor Destroy;
End;
type
TForm7 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7;
c1: class1;
c2: class2;
implementation
{$R *.dfm}
Constructor class1.Create;
begin
c2 := class2.Create;
end;
Destructor class1.Destroy;
begin
//
end;
Constructor class2.Create;
begin
if Assigned(c1) then showmessage('ok') else showmessage('error');
end;
Destructor class2.Destroy;
begin
//
end;
procedure TForm7.FormCreate(Sender: TObject);
begin
c1 := class1.Create;
end;
end.
|
20091111-EE-VQP-92 - Hierarchy / EE_QW_EXPERT_20070906