In the code below I am using the variable f as an abbreviation for a field named FDataModule. The idea is to check that the data module exists an display a related form. If the data module does not exist, it is created before.
I thought that by f:= FDataModule following by the Assigned procedure would work as I expected, f would not be nil iif FDataModule was already created. However in this case f is always nil and new forms are always opened.
What is wrong with the code?
procedure TdmCentral.actionExecute(Sender: TObject);
var
f: TdmDateModule;
begin
{
f := FDataModule;
if not Assigned(f) then
begin
f := TdmDataModule.Create(self);
end;
f.DisplayForm;
}
if not Assigned(FDataModule) then
begin
FDataModule := TdmDataModule.Create(self);
end;
FDataModule.DisplayForm;
end
;