How to identify which form has changed the property of a component?

Asked

Viewed 733 times

3

It is possible for me to identify which form has changed the property of a particular component?

For example, I have a Data Module with a ZTable which is accessed by several forms at the events onClose of those forms, would need to check if my zTable was opened on itself form. If it is, I close the zTable, if it wasn’t, I don’t close.

  • For me it is not very clear what you are saying. Could put more information. I don’t know if this solves your problem, but it is good practice to close the query when you are no longer using.

  • From what I understand, you have an object shared among several Rfms and want to know who originally opened this object to close it. That’s right?

  • That’s right... :)

1 answer

4


The best way to do this (for me who 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 altering 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:

  1. Create a new Unit;
  2. Put this Unit in the clause uses of each Form and of Data Module what to use;
  3. When opening the table from the form, use table.OpenFromForm;
  4. When closing the table by form, use table.CloseFromForm;

In the Data Module use:

if table.IsFormOpened then
begin
  table.isFormOpened := False;
  table.Close;
end;
  • Dude, this is exactly what I needed... I just didn’t get one thing, where I insert this code into the Data Module?

  • Put in the Unit of Clause 1 that you will create

Browser other questions tagged

You are not signed in. Login or sign up in order to post.