hey im working on delphi 7, and i have a scenario for a available form, i have two forms
1. FormOne
2. FormTwo
FormOne has a button
which create the FormTwo on button click
var
Form2:TForm2;
begin
Form2:=TForm2.Create(nil);
Form2.ShowModal ;
Form2.Free;
end;
On Form2 there is a button which i need to disable..(on some conditions)..
so on activate of Form2 i did this
if assigned(Form2) then
begin
Form2.Button1.Enabled:=False;
end;
that is im checking if the form is created then disable the button.. since the code is in Onactivate meaning the form2 is already created according to this the delphi form liyfe cyle is
OnCreate -> OnShow -> OnActivate -> OnPaint -> OnResize -> OnPaint
..so the button1 should be disabled..but it NOT disabled.
I guess Form2
is a local variable in your button click handler; in your OnActivate
handler your are testing a global Form2
variable from the unit where TForm2
is defined; the second is not assigned if TForm2
is not autocreated form.