herculanojs Posted July 6, 2016 Posted July 6, 2016 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; Quote
ZigZig Posted July 6, 2016 Posted July 6, 2016 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. Quote
zilav Posted July 7, 2016 Posted July 7, 2016 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. Quote
herculanojs Posted July 7, 2016 Author Posted July 7, 2016 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. Quote
zilav Posted July 8, 2016 Posted July 8, 2016 Unlike Javascript we don't have promises on server side, so "callback hell" is the only option for now unless UniGUI will add a similar feature or you want to fiddle with js on client side yourself. Quote
Oliver Morsch Posted July 8, 2016 Posted July 8, 2016 Or make your own blocking dialogs whitout need for callbacks. 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.