dpfmp Posted February 9, 2019 Share Posted February 9, 2019 Hi, // test procedure TMainForm.UniButton1Click(Sender: TObject); var iArr: array of integer; begin SetLength(iArr,2); try MessageDlg('Yes or No', mtConfirmation, mbYesNo, procedure (Sender: TComponent; Res: integer) begin case Res of TModalResult(mrYes): iArr[0] := 0; // <-- AV TModalResult(mrNo): iArr[1] := 1; // <-- AV end end); finally SetLength(iArr,0); end; end; The code reaches the "Finally" block before MessageDlg shows up and causes an AV since the array was freed. What if we need to change a dynamically created structure ( memory table, array etc ) inside a "try..finally" by calling a function in the MessageDlg callback that would modify the structure? Is this the wrong approach? Thank you, Denis Prince D10.1 UniGUI 1.50.0.1484 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 9, 2019 Share Posted February 9, 2019 Hi, Please see the documentation: http://unigui.com/doc/online_help/synch-and-asynch-operations.htm Quote Link to comment Share on other sites More sharing options...
dpfmp Posted February 10, 2019 Author Share Posted February 10, 2019 Hi Sherzod, EnableSynchronousOperations true Not blocking the thread ================================================= procedure TMainForm.UniButton1Click(Sender: TObject); var iArr: array of integer; begin SetLength(iArr,2); try MessageDlg('Yes or No', mtConfirmation, mbYesNo, procedure (Sender: TComponent; Res: integer) begin case Res of TModalResult(mrYes): iArr[0] := 0; // <-- AV TModalResult(mrNo): iArr[1] := 1; // <-- AV end end); finally SetLength(iArr,0); end; end; Blocking the thread (this works fine in my test) ================================================ procedure TMainForm.UniButton2Click(Sender: TObject); var iArr: array of integer; Res: TModalResult; begin SetLength(iArr,2); try Res := MessageDlg('Yes or No', mtConfirmation, mbYesNo); case Res of mrYes: iArr[0] := 0; mrNo: iArr[1] := 1; end finally SetLength(iArr,0); end; end; Do we use the callback in MessageDlg when we don't want to block the thread? Thank you again for your help, Denis Prince Quote Link to comment Share on other sites More sharing options...
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.