Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do get my dialog to return mrOk?

Status
Not open for further replies.

Vovin

Programmer
Aug 24, 2003
63
GB
Hi,

this should be really simple but I'm tearing my hair out trying to get it. I'm new to Delphi (I'm a C++ programmer).

I have a dialog with an 'Ok' button on it. I've set the ModalResult property of the button to be mrOk. I've set the dialogs BorderStyle to bsDialog.

Here is some of my code:
buttonSelected := certmgr.ShowModal;
If (CertMgr.ipmCertMgr1.CertHandle <> 0) and (buttonSelected = mrOK) Then Begin

The trouble is that buttonSelected always has the value 2 and mrOk has a value of 1. Why can't I get the dialog to return mrOk when I click the 'Ok' button.

I think Delphi hates me (I think it knows I'm a C++ programmer) and it's doing everything it can to deliberately annoy me (it's the best explanation that I can come with as to why this isn't working).
 
Yep, youre right. Delphi must hate you ;-)

Well, I made a project with 2 forms, and in the mainform (Form1) I added a button and wrote following code in it:

if Form2.ShowModal = mrOK then
ShowMessage('OK')
else
ShowMessage('Something else!');

In Form2, I added 2 buttons. One with property ModalResult = mrOK and one with modelResult = mrCancel.

Everything worked fine...


Might CertMgr.ipmCertMgr1.CertHandle be the problem?



//Nordlund
 
Hi Nordlund thanks for the quick reply,

I had a go at creating a new project with 2 forms and used your code and it works fine.

My project still doesn't work though. The dialog that I'm calling showModal on was written by someone else. Is it possible that they may have changed a property on their dialog that would stop this from working correctly?

Maybe it's my imagination but I'm sure Delphi %-( sneered at me a minute ago.
 
Search for Modalresult in the popup dialog.
The one who has made the form might have used the ModalResult property in a wrong way...


//Nordlund
 
Check the OnClick event of the button to make sure there's nothing in there that could be affecting the result.

 
Thanks for the help guys. Here is the button event code:

procedure TCertMgr.cmdOKClick(Sender: TObject);
begin
CertMgr.Close ;
end;

I had a search through the code for ModalResult but nothing came up.

I think I'll maybe have a go at recreating the dialog from scratch rather than waste any more time trying to track down the problem. It's a bit worrying though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top