Return values to Dynamic Forms in Delphi

Asked

Viewed 352 times

1

I intend to create an unlimited number of instances of frmPai (MDI) that is created dynamically as follows:

class procedure TfrmPai.ShowForm;
var
  frmPai: TfrmPai;
begin
  frmPai := TfrmPai.Create(nil);

  frmPai.Show;
end;

When closing run:

procedure TfrmPai.FormClose(Sender: TObject; var Action: TCloseAction);
begin   
  Action := caFree;
end;

That one form has a button that calls the frmFilho to process and display a Progress bar. To create the frmFilho, a Procedure of callback to notify to the frmPai that the processing has ended and display the result

Callback of frmPai:

procedure TfrmPai.MyCallback(icont_process: Integer);
begin
  Self.LabelResultado.Caption := IntToStr(icont_process)+' itens processados.');
end;

Creation of frmFilho:

class procedure TfrmFilho.ShowForm(AMyCallback: TMyCallback);
var
  frmFilho: TfrmFilho;
begin
  frmFilho := TfrmFilho.Create(nil);

  with frmFilho do
  begin
    FMyCallback := AMyCallback;

    Show;
  end;
end;

The problem occurs in the execution of Callback...

How to check if the frmPai to which the result should return has not been closed while the frmFilho was processing, since frmPai is created dynamically?

  • I believe the problem is in the creation of the Son, notice that you are creating him as nil. You shouldn’t pass the name "Dad"?

  • that was intentional... I needed them to be independent, so I could close formPai, but not in that case, I wouldn’t run callback (because I could give access Violation)

1 answer

0


You can have one property in the child that identifies the father, and another in the father that identifies the child(s). Before closing the father, go through the children saying "that they are now orphans" (adjusting the corresponding property to nil). Something similar to Tcomponent Freenotification.

Browser other questions tagged

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