Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Pass a variable from one form to anotherHelpful Member! 

vincentw56 (IS/IT--Management) (OP)
25 Apr 03 14:12
I am still learning Delphi and getting away from VB. How do you pass the contents of one from variable to another?  Right now I am using a datamodule to do it, but wanted to see if there is a better way.  Thanks.

Vincent
Zathras (Programmer)
25 Apr 03 14:30
There are so many ways...

Can you be a little more specific about what you want to do?  Are you using .ShowModal?  Are you creating the form yourself or letting Delphi do it?  Do you have the first form referenced in a uses statement within the second form's unit?

One of the easiest ways is simply to qualify with the object name, e.g. in Form2:

   ShowMessage(Form1.FStringVariable);

where FStringVariable is defined in the public section of the interface for Form1.
vincentw56 (IS/IT--Management) (OP)
25 Apr 03 15:17
Actually what you showed me is exactly what I wanted. That is pretty much the same with VB except I did not make it public on Form1.  Thanks for the help once again.

Vincent
Helpful Member!  richardchaven (Programmer)
28 Apr 03 15:56
Another way to do it is to treat the form as a sub-class of TForm, which it is! <s>

Instead of exposing fields, you can create a public or published property of a form class that can use accessors and mutators to set the caption, change the color or position, etc. Even though these new properties do not appear in the Object Inspector (at least not easily), they are still part of the class.

In fact, creating properties of forms makes them encapsulated, robust, and even polymorphic!. For Instance, you can have a form that displays customer information. It might have a property named "CustomerID" with a protected, virtual mustator (e.g. SetCustomerID). This mutator finds the correct row in the DataSet, not the Menu.OnClick or anything else. Any piece of code can just call

   with TCustomerForm.Create(Application) do
   begin
       CustomerID := WhatTheUserWants;
       Show;
   end;


Any change to the CUSTOMER table (or tables) is encapsulated inside this form.

You can create a descendent of that form that allows specific editing of customer information. That descendent will override SetCustomerID and do the extra things it needs to for editing.

Cheers

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close