Rafael P Posted July 8, 2020 Posted July 8, 2020 Hi there, Frst one, i need to analyze what i'm doing wrong. I have a function to provide and return date values once user was clicked on it. And i need the Result load these values i have it. See the code below: function TDmPrincipal.RetornaIntervaloData(pQtdeDias: Integer): TIntervaloData; var pResult : TIntervaloData; begin try if pQtdeDias > 0 then begin Result.dtIni := date - pQtdeDias; Result.dtFin := date; Result.pExtenso:= 'De: ' + FormatDateTime('dd/mm/yyyy', pResult.dtIni) + ' a ' + FormatDateTime('dd/mm/yyyy', pResult.dtFin); Exit; end; FrmIntervaloData.ShowModal( procedure(Sender: TComponent; Result: Integer) begin pResult.dtIni := FrmIntervaloData.dtInicial.DateTime; pResult.dtIni := FrmIntervaloData.dtInicial.DateTime; pResult.pExtenso:= 'De: ' + FormatDateTime('dd/mm/yyyy', pResult.dtIni) + ' a ' + FormatDateTime('dd/mm/yyyy', pResult.dtFin); end); finally end; And i have a cons defined before: TIntervaloData = record dtIni: TDate; dtFin: TDate; pExtenso: String; end; So, i need the Result's procedure return those values like .dtIni and dtFin. Is there any workaround for this? , Regards. Quote
Pep Posted July 8, 2020 Posted July 8, 2020 Hello Rafael, Is not a good idea use a function for that purpose (using a anonymous procedure inside). Maybe you can try this alternative method: procedure TDmPrincipal.AskIntervaloData(pQtdeDias: Integer); var V: TIntervaloData; begin if pQtdeDias > 0 then begin V.dtIni := date - pQtdeDias; V.dtFin := date; V.pExtenso := 'De: ' + FormatDateTime('dd/mm/yyyy', pResult.dtIni) + ' a ' + FormatDateTime('dd/mm/yyyy', pResult.dtFin); RetornaIntervaloData(V); end else begin FrmIntervaloData.ShowModal( procedure(Sender: TComponent; Result: Integer) begin V.dtIni := FrmIntervaloData.dtInicial.DateTime; V.dtIni := FrmIntervaloData.dtInicial.DateTime; V.pExtenso := 'De: ' + FormatDateTime('dd/mm/yyyy', V.dtIni) + ' a ' + FormatDateTime('dd/mm/yyyy', V.dtFin); RetornaIntervaloData(V); end); end; end; procedure TDmPrincipal.RetornaIntervaloData(Value: TIntervaloData); begin ShowMessage(Value.pExtenso); ... end; 1 Quote
Rafael P Posted July 8, 2020 Author Posted July 8, 2020 Thank you, really appreciate your help! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.