Jump to content

How to Return Value From Result Procedure?


Rafael P

Recommended Posts

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. 

Link to comment
Share on other sites

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;

 

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...