The best way to do this (for me I do not know if there is an existing pattern) is to create a Helper
for the zTable object.
A helper is a Delphi class helper that you can use to add more functionality to a class, without necessarily changing its structure, or making a class derived from it. That is, you will be able to continue using the component directly from the Delphi component palette.
TTableHelper = class helper for TzTable
public
function OpenFromForm: boolean;
function CloseFromForm: boolean;
IsFormOpened: boolean;
IsFormClosed: boolean;
end;
function TTableHelper.CloseFromForm: boolean;
begin
try
Self.Active := False;
Result := True;
ISFormClosed := True;
except
Result := False;
end;
end;
function TTableHelper.OpenFromForm: boolean;
begin
try
Self.Active := True;
Result := True;
ISFormOpened := True;
except
Result := False;
end;
end;
Do the following:
Create a new Unit
;
Place this Unit in the uses
clause of each Form
and Data Module
to use;
When opening the table by the form, use table.OpenFromForm
;
When closing the table by the form, use table.CloseFromForm
;
No Data Module
use:
if table.IsFormOpened then
begin
table.isFormOpened := False;
table.Close;
end;