Forum > Database
Showmodal affects SQLQuery behavior
mikeosullivan:
You ask what does not work. When the user clicks on the "Yes" button the record should get deleted. This does not happen although it did work pefectly before with previous versions of Lazarus and earlier versions of the OS. Thanks for all your comments but I'm still mystified ...
rvk:
Then there is something else wrong.
It's not that code (although I still think the Form2.Close is wrong).
But we don't see the rest of the code.
You can put a showmessage('hello'); inside the begin/end to see if it gets there.
If it does, there is another reason why it's failing.
If it doesn't then your candelete isn't set correctly.
mikeosullivan:
I've done that and even made the showmessage "Hello" conditional upon canDelete = True so all the code executes correctly. I agree with you that something else is wrong but it's difficult to know what it is. Thanks for introducing me to TQuestionDlg - I didn't know about that - could be very useful indeed.
As regards Form2.Close, I've tried Self.Close and Close but the same happens. The record will not get deleted.
canDelete is set as a global variable in unit1.
Thanks for your comments - I appreciate them.
rvk:
--- Quote from: mikeosullivan on August 16, 2023, 11:02:13 pm ---As regards Form2.Close, I've tried Self.Close and Close but the same happens. The record will not get deleted.
--- End quote ---
No, it's not your actual problem but you should use
ModalResult := mrOk;
Or
ModalResult := mrCancel;
Instead of Form2.Close.
You can even use the result of ShowModal ( it's a function) instead of candelete.
This is better code.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if Form2.ShowModal = mrOk thenbegin SQLQuery1.Delete; SQLQuery1.ApplyUpdates; SQLTransaction1.Commit;end;and
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm2.btnYesClick(Sender: TObject);begin ModalResult := mrOk;end; procedure TForm2.btnNoClick(Sender: TObject);begin ModalResult := mrCancel;end;No need for candelete.
But as stated, your problem still remains.
There is probably something wrong with the deletesql statement.
(Or something else, but we can't see that without more code)
mikeosullivan:
I've tried your code but the same problem persists. I really don't understand what's going on here.
If I comment out the 2 lines
//unit2.Form2.ShowModal;
//if canDelete then
.......
record deletion executes perfectly but without any warning to the user.
Thanks again for your help.
Navigation
[0] Message Index
[#] Next page
[*] Previous page