Jump to content

Result function - MessageDLG


herculanojs

Recommended Posts

Hello friends
But a theme for your help.
Is there any way to return the result of a function falling within the scope of the message callback?
 
Olá amigos
Mais um tema para vossa ajuda.
Há alguma forma de retornar para o result de uma function estando dentro do escopo do callback message?
 
Example:
 
function teste: boolean;
begin
         result: = false;
         MessageDlg ('My question?' MtConfirmation, mbYesNo,
             procedure (Sender: TComponent; Res: Integer)
             begin
               Res case of
                 mrYes:
                 begin
                           // Run code
 
                          is there any chance of returning to the function?
                 end;
               end;
             end
           );
end;

 

Link to comment
Share on other sites

If I understand your need, you can try something like this (I didn't test it but it should work):

 

 

function teste: boolean;
begin
         result: = false;
         UniSession.myModalResult:=mrNone;//myModalResult is a public property that you must define in UniSession.
         MessageDlg ('My question?' MtConfirmation, mbYesNo,
             procedure (Sender: TComponent; Res: Integer)
             begin
               Res case of
                 mrYes:
                 begin
                           // Run code
                         
                          is there any chance of returning to the function? // yes, by using a session property
                 end;
               end;
               UniSession.MyModalResult:=Res;
             end
           );
          While UniSession.MyModalResult=mrNone do
          begin
            //do nothing
          end;
        
         //The following code will not be executed until MessageDlg get a modal result
        // ie : if UniSession.MyModalResult=mrOK then ...
end;

 

 

 

But IMHO, it is not a good practice.

Link to comment
Share on other sites

At least put something like Sleep(100) in while loop. But it is indeed a bad practice.

I recommend to put the code you want to execute after a dialog in a separate function/method and call it within callback, that way you'll still get access to all the properties of a parent form/frame without cluttering the callback code itself.

Link to comment
Share on other sites

Yes already use the callback for that. However there are situations where you make an inquiry and performs something. Then there is another question to something else, that linked to the previous process. Callback for each situation nested within other is not the best practice.

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