Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Passing variables between forms

zicheziche Posts: 47Member
In my application I have a form that launches another.

After some processing in the 2nd form, and the user clicking a button, I want a TStings or string value to be returned to the calling form.

How do I go about this?

Obviously I not looking for some circular uses arrangement where FORM1 has FORM2 in its uses section and FORM2 has FORM1 in its.

Some example code would be greatly appreciated.

Comments

  • zibadianzibadian Posts: 6,349Member
    : In my application I have a form that launches another.
    :
    : After some processing in the 2nd form, and the user clicking a button, I want a TStings or string value to be returned to the calling form.
    :
    : How do I go about this?
    :
    : Obviously I not looking for some circular uses arrangement where FORM1 has FORM2 in its uses section and FORM2 has FORM1 in its.
    :
    : Some example code would be greatly appreciated.
    :
    :
    It is not that difficult. Each form has a global variable, which contains it reference. This reference is nothing more than any other object, thus accessing one form from the other is coded like this:
    [code]
    procedure TForm1.ButtonClick(Sender: TObject);
    begin
    Memo1.Lines := Form2.Memo1.Lines;
    end;
    [/code]
    This sample code copies the Lines of the Memo on Form2 to the Memo on Form1.
    If you want Form2 to access Form1, you need to create another uses list under the implementation:
    [code]
    implementation

    uses
    Unit1;

    procedure TForm2.ButtonClick(Sender: TObject);
    begin
    Memo1.Lines := Form1.Memo1.Lines;
    end;
    [/code]
Sign In or Register to comment.