How to update TEdit control on Main form with the input of a TEdit on a dialog after pressing ok button?

Hi Guys!

I have a Main Form with a TEdit and a TButton on it. Also I have a Dialog with a TEdit on it plus two buttons. CLicking the button on the main form pops up the dialog with the TEdit on it. Now I want to update the TEdit on the mainform with the contents of the TEdit on the dialog after button1 from the dialog is pressed while pressing button2 should cancel this operation leaving the edit on the mainform untouched.

My goal: popping up the dialog, insert some characters into the dialogs TEdit and only after I press OK button of the dialog, the contents of hte main forms TEdit is changed (immediately) otherwise it remains the same (untouched).

I gave my best shot this afternoon but failed to achieve this. Providing a working sample grants you the points. Let me know if my information is insufficient ok?

Regards from Holland,

PeterdeB

PeterdeBAsked:
Who is Participating?
 
TheRealLokiConnect With a Mentor Senior DeveloperCommented:
create a standard dialog with 2 buttons (file - new- dialog- standard dialog) - we'll assume this is "unit2/form2"
the "ok" button has a modalresult of mrOK, and the "cancel" button by default has a modalresult of mrCancel;
put your edit on there and call it something unique like eMyDialogEddit, and call it like this from your main form

uses unit2;

with TForm2.create do
try
    if ShowModal = mrOK then // ok button pressed
      edit1.text := eMyDialogEddit.Text;  
finally
    free;
end;
0
 
LRHGuyCommented:
in dialog form:

on buttonclick:

  mainform.teditname.text:=dialogform.teditname.text

in other words, in the button click on the dialog that is "accepting" the input, push the value into the main form by referencing the field on the main form. You'll need to include the main form's unit in the implementation section of the dialogue unit.
0
 
TheRealLokiSenior DeveloperCommented:
oops, that should say with TForm2.create(self)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
PeterdeBAuthor Commented:
Hi TheRealLoki you bring a smile upon my face with your comment since I figured that out by now too LOL!! Nevertheless it goes without saying that you get the points, your answer is PERFECT!!

Needless to post the code here but I'll do it anyway:

 with TfrmWizard.create(Self) do
try
    if ShowModal = mrOK then // ok button pressed

        gbTabForum.Caption := edit1.text;
         edtURL.Text := edit2.Text;
       edtUserName.Text := edit3.Text;
        edtPassword.Text := edit4.Text;
       edtBtnText.Text :=  edit5.Text;
finally
    free;
end;

Tnx a lot!!!

PeterdeB
0
 
TheRealLokiSenior DeveloperCommented:
you're welcome. don't forget to use a begin..end block if you want to set multiple edit boxes etc.

btw, if you wanted to use the same dialog to "edit" your settings, you could do

with TfrmWizard.create(Self) do
try
// set text
        edit1.text := gbTabForum.Caption;
        edit2.Text := edtURL.Text;
        edit3.Text := edtUserName.Text;
        edit4.Text := edtPassword.Text;
        edit5.Text := edtBtnText.Text;
// now display the dialog so the user can edit
    if ShowModal = mrOK then // ok button pressed
    begin // YOU NEED THIS BLOCK IF YOU ARE SAVING MORE THAN 1
        gbTabForum.Caption := edit1.text;
        edtURL.Text := edit2.Text;
        edtUserName.Text := edit3.Text;
        edtPassword.Text := edit4.Text;
        edtBtnText.Text :=  edit5.Text;
    end; // of user pressed OK
finally
    free;
end;
0
 
PeterdeBAuthor Commented:
Thanks TheRealLoki! I was just struggling with several TEdits so your comment helped me out once more!!

My regards!

PeterdeB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.