Jump to content

Method to return another object FORM


picyka

Recommended Posts

How to implement a method that seeks an object from another form

 

something like the UniCalendarDialog

 

 

 

UniCalendarDialog1.Execute;

TuDialogsFrame.UniCalendarDialog1Confirm procedure (Sender: TObject);
begin
  UniLabel2.Caption: = DateToStr (UniCalendarDialog1.Date);
end;

or something like:

 

 

 

UniGUIDialogs.MessageDlg ('Confirm deleting the selected record?' MtConfirmation, mbYesNo, _Confirm);

TFCidade._Confirm procedure (AResult: Integer);
begin
  AResult case of
	mrYes:
  	begin
		FCidadeService.Delete (Self.FCidade);
		Self.Close;
  	end;
	mrNo: edNome.SetFocus;
  end;
end; 

Link to comment
Share on other sites

 type
 TResultObjCallBackAnonProc = reference to procedure (AResult : TAbstractBO);

procedure TFConsPadraoObj.InstanceForm(AObj : TAbstractBO; AService : TClass; AProc : TResultObjCallBackAnonProc);
begin
 Self.FListFilter := TObjectList<TFilterColumn>.Create;
 Self.FService := AService;
 Self.FResultObj := AObj;
 Self.CreateClintDataSet(Self.FResultObj);
 Self.ShowModal;

 AProc(Self.ResultObj);
end;


 FConsPadraoObj.InstanceForm(Self.FCidade.Estado, TClass(Self.FCidadeService),
                             procedure(ResultObj : TAbstractBO)
                             begin
                               ResultObj.AssignTo(Self.FCidade.Estado);
                             end)

 

 

 

I could not understand where food

 

AProc (Self.ResultObj);

 

why so ResultObj User has value after selecting a row.

 

Any tips?

Link to comment
Share on other sites

AProc(Self.ResultObj) is called before form is closed since Self.ShowModal doesn't block execution in unigui. You need to pass that anonymous function to your form and call it in Form.OnClose event.

Link to comment
Share on other sites

Yes even thought about it the more I like this method in food on close if it is a parameter to procedure

"procedure TFConsPadraoObj.InstanceForm (AObj: TAbstractBO; AService: TClass; AProc:TResultObjCallBackAnonProc); "

 

That could not understand ...

Link to comment
Share on other sites

Solution:

 

type
 TResultObjCallBackAnonProc = reference to procedure (AResult : TAbstractBO);

 private
   { Private declarations }
   FResultObjCallBackAnonProc : TResultObjCallBackAnonProc;


procedure TFConsPadraoObj.InstanceForm(AObj : TAbstractBO; AService : TClass; AProc : TResultObjCallBackAnonProc);
begin
 Self.FListFilter := TObjectList<TFilterColumn>.Create;
 Self.FService := AService;
 Self.FResultObj := AObj;
 Self.CreateClintDataSet(Self.FResultObj);
 Self.ShowModal;

 FResultObjCallBackAnonProc := AProc;
end;

procedure TFConsPadraoObj.UniFormClose(Sender: TObject; var Action: TCloseAction);
begin
 FResultObjCallBackAnonProc(ResultObj);
end;

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...