[Borland]Make a custom Dialog Form...please help me!

Started by
3 comments, last by Link 20 years, 9 months ago
I have a main Form named Form1 (original eh?? ) And i coded also another Form, simple with 3 LabelText, 2 TEdit, and 2 buttons: OK and cancel... When i click New in the File>New menu of Form1 i would show the Form2 (as a dialog) and make unusable (disabled) the main Form (Form1), only when i press OK button or Cancel button a can came back at the Form1 (so hide Form2 and make enabled Form1)... Please Borland user help me!! Tnx a lot!
Advertisement
There should be a ShowModal function of your dialogue. This will display the form and won't let the user click on the other ones. You can check the return value to see what button the user pressed (it's of type TModalResult). Something like this:

if (Form2->ShowModal() == mrOK)  // do something here 


You can also use the ModalResult property after a ShowModal to get the result at a later time:

Form2->ShowModal();if (Form2->ModalResult == mrOK)  // do something here 


Now, something to remember: you should set the ModalResult of the to-be-shown form. The form will close the moment you assign a value to its ModalResult property. The easiest way to do this is to put down some TBitBtns and set their "Kind" property to bkOK and bkCancel. You can also do it in code.

[edited by - Alimonster on July 3, 2003 1:41:12 PM]
Tnx Alimonster

now i try to understand how i must do with 'TBitBtns and set their "Kind" property to bkOK and bkCancel'... in others way can you help me if i don't success?

[edited by - Link on July 3, 2003 5:21:54 PM]
No problem. The ModalResult property of your form controls what value is passed back to the main form -- you need to know what action the user took and that''s how you get it. This means that your dialogue form needs to change the ModalResult at appropriate times. The two most common results are mrOk and mrCancel (but there are others).

Now, you have the option of changing the ModalResult at any time and in any way you want. This is handy.

The first choice is to add a line of code inside your dialogue form (maybe on a button OnClick event) that does something like this: "ModalResult = mrOK;" or "ModalResult = mrCancel;". That, in fact, is the most obvious way to do it. However, a couple of components can take care of this for you. Place a TButton or a TBitBtn onto your form and notice that they have the "ModalResult" property too. If you change this then your buttons will close the form with the right result even without any code at all! I.e., you want one button with a ModalResult of mrOk and another with mrCancel (assuming you want the dialogue to have those options, and not just a close. Depends on your needs obviously.).

You can put down two TButtons (standard tab) or two TBitBtns (additional tab). The TBitBtns have several standard settings, such as "Ok", "Cancel", "Help", and so on, and each setting has a little picture (like a tick or a cross). You can use the Kind property of the TBitBtns to change what happens when the user clicks the button -- just change the values by selecting them at design-time. No code is needed here.

Make any more sense?
I understood how to use ModalResult, the only trouble is this:
i make 2 button ok and cancel, at the first i set mrNone, at the second one i set mrCancel...
When i push the ok button in the Onclick funstion i set his modalresult at mrOk or mrNone by the result of a if cicle...
it work but when i push the ok button and if cicle set it to mrCancel, at the first time it doesn't work, it sent mrOk anyway, while at the second time it came setted correctly... why?

i show you a little of code:
it is the function (inside Form1) that show the form2 (note, i use extern variables for w):
   Form2->ShowModal();   if (Form2->ModalResult == mrOk) Label2->Caption = w;   


now the onclick function in the form2:
  if (a && b && c && d)  {   w = (int)iw;   Label6->Caption = "ok";   ButtonOk->ModalResult = mrOk;  }  else  {   Label6->Caption = "no";   ButtonOk->ModalResult = mrNone;  }   


I explain better: if i sent mrNone how value it close anyway the form2, while if i cameback on file>new and recall Form2 and if cicle set also to mrNone it now doesn't close te window... how can i make it works correctly?

[edited by - Link on July 3, 2003 7:04:09 PM]

This topic is closed to new replies.

Advertisement