Return Values for Dynamic Forms in Delphi

1

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

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

  frmPai.Show;
end;

When I close I run:

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

This form has a button that calls frmFilho to render and display a progress bar . To create frmFilho , a procedure callback is requested to notify frmPai that the processing is finished and display the result

Callback of frmPai :

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

Creating 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 when executing Callback ...

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

    
asked by anonymous 03.04.2017 / 16:34

1 answer

0

You can have one property on the child that identifies the parent, and another on the parent that identifies the child (ren). Before closing the father, walk the children saying "they are now orphans" (adjusting the corresponding property for nil). Something similar to TComponent's FreeNotification.

    
04.04.2017 / 23:55