Jump to content

please help, Function always return same value


NS Angga

Recommended Posts

I create function in a unit that i created, like this :
 
 
function ConfirmMsg(MsgForm : TUniForm; strMsg : string) : Boolean;
var
  fnConfirm : Boolean;
begin
  Beep;
  MsgForm.MessageDlg(strMsg, mtConfirmation, mbYesNo,
    procedure(Res: Integer)
    begin
      case Res of
        mrYes : fnConfirm := True;
        mrNo  : fnConfirm := False;
      end;
    end
  );
  Result := fnConfirm;
end;
 
 
when that function i call always return value true or mrYes, even though i chose button "no"
 
==
 
other case, 
 
i created function in the same unit, like this :
 
 
function GetResultModalForm : Boolean;
var
  intResult : integer;
  //frmTest : TfrmTest;
begin
  result := Null;
  //frmTest := TfrmTest.Create(UniApplication); --> i made that syntac be comment, cause always return error
 
  if frmTest.ShowModal(
    procedure(AResult:Integer)
    begin
      if AResult = 1 then intResult:= AResult;
    end
  );
 
  if intResult= 1 then Result = true else Result := False;
 
end;
 
two function above always return same value,  why?
 
 
somebody can explain and correct my syntac

 

Link to comment
Share on other sites

MessageDlg, ShowModal, ShowMessage don't "stop" the code execution in UniGui/WebMode, so you do:

 

(1) You start a Modal Dialog and

(2) give a (the initial !) result back.

(3) After you click on OK/Cancel/Yes/No/...

(4) the anonymous procedure (callback procedure) is called

 

=> (2) is before (3) and (4) so it can't contain the future result !!!

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...