Solved

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

Posted on 2004-11-02
234 Views
Last Modified: 2010-04-05
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

0
Question by:PeterdeB
    6 Comments
     
    LVL 7

    Expert Comment

    by:LRHGuy
    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
     
    LVL 17

    Accepted Solution

    by:
    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
     
    LVL 17

    Expert Comment

    by:TheRealLoki
    oops, that should say with TForm2.create(self)
    0
     

    Author Comment

    by:PeterdeB
    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
     
    LVL 17

    Expert Comment

    by:TheRealLoki
    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
     

    Author Comment

    by:PeterdeB
    Thanks TheRealLoki! I was just struggling with several TEdits so your comment helped me out once more!!

    My regards!

    PeterdeB
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now