Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheritance Question 1

Status
Not open for further replies.

Delphard

Programmer
Jul 22, 2004
144
0
0
RS
Form1 is ancestor Form, and had this code in Form1.FormClose:
...
Action:= caFree;
Form1 := nil;
end;

Form2 is derived from Form1 (TForm2 = class(TForm1).

What should write instead of Form1 := nil in Form1.FormClose to be sure that (inherited) Form2 is also nil after Close?
 
All that's true, and I know that!
We are just one step close to solution!
I need code that will be Free (and nil) closed descendant Form:

Code:
procedure TGForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 Action:= caFree;
 GForm := nil;  // here need to be something different to close any of TXForm, TYForm and TZForm (instead of TGForm), but what?
end;
 
I think there is a misunderstanding here, Form1 is a variable which points at an instance of tForm1. That instance of tForm1 does not know about the variable Form1 and the only reason the first example works is because Form1 is global, and you *know* that it is pointing at the tForm1 instance because that is the variable delphi has used in the project file when auto-creating the form with application.CreateForm.

If you want to clear the reference the tForm would need a reference to its reference. So...

type
pForm = ^tForm; // declare pointer to tForm Variable

tForm
public
MyDelphiReference: pForm;

/* snip */

procedure tForm1.FormClose
begin
MyDelphiReference^ := nil;
end;

And then in the project file after the create forms you would put

Application.CreateForm(tForm1, Form1);
Application.CreateForm(tForm2, Form2);

Form1.MyDelphiReference = @Form1;
Form2.MyDelphiReference = @Form2;

{ or something like that, I've not tried it }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top