Solved

Passing Parameters trough Forms.

Posted on 1998-09-08
58
199 Views
Last Modified: 2010-04-06
I have a MDI application that creates forms dynamically.  I want pass parameters from MDI Children Forms to other forms created by the MDI Children Forms uppon a mouse click.
0
Comment
Question by:jconde2
  • 22
  • 14
  • 11
  • +4
58 Comments
 
LVL 1

Expert Comment

by:Edo082297
ID: 1338997
Hi jconde2

  What exactly do you want to do?

Edo


0
 

Author Comment

by:jconde2
ID: 1338998
I created a MDI Child form with

var
  Child: TClass_Name;
begin
  Child := TClass_Name.Create(Application);

from my MDI parent from  (FORM1).  Once the child is created (FORM2), I created another form in the same way (FORM3), and this form needs to get a few parameters from the second form created.

In other words, FORM3 needs to receive some string values from FORM2 and I don´t know how can I accomplish this.

Thanx

jconde
0
 

Author Comment

by:jconde2
ID: 1338999
I created a MDI Child form with

var
  Child: TClass_Name;
begin
  Child := TClass_Name.Create(Application);

from my MDI parent from  (FORM1).  Once the child is created (FORM2), I created another form in the same way (FORM3), and this form needs to get a few parameters from the second form created.

In other words, FORM3 needs to receive some string values from FORM2 and I don´t know how can I accomplish this.

Thanx

jconde
0
 

Author Comment

by:jconde2
ID: 1339000
Adjusted points to 100
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339001
Hi jconde2, I did this myself once...

This isn't at all difficult you know.

Let presume the name of Form2 is Form2:-) and of Form3 is Form3

The parameters are passed after you've created your Form3 (Form2 already exists)

Form3 := ...Create...
From3.Parameter1 := Form2.Parameter1;
Form3.Parameter2 := Form2.What_Do_I_know;
..

Thats all you got to do...

You know your childs names, because they are kepped in a list.

 MDIChildren[I].....

Or you can use you're own list with TForms if this would make your life easier.... maybe every different childtype in another list... etc.

Regards, Zif.
0
 

Author Comment

by:jconde2
ID: 1339002
Thought you where quitting ZiF?.....

Anyways, Its great to have you arround here!

Zif, the problem I have is the following......
I need the parameters when the form is created!!

Can you help me out please?

I'll increase the points too!
Be cool
jconde
jconde
0
 

Author Comment

by:jconde2
ID: 1339003
Adjusted points to 101
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339004
Yes, I'm quiting, but just for a few weeks... need a vacation...

What is the really problem, because I'm missing here something.... Is the problem that the form isn't created yet or is it because you need to assing the parameters before creating?

Zif.
0
 

Author Comment

by:jconde2
ID: 1339005
That's good to know!  As someone stated, It's great to have "Real" experts arround!

this is the code I have:

var
  Design_Table: TDesign_Table;
begin
  Design_Table := TDesign_Table.Create(Application);
  Design_Table.Current_DB_S := Database.Current_DB;
  Design_Table.Port_S := Database.Port2;
  Design_Table.Host_S := Database.Server2;
  Design_Table.Password_S := Database.Password2;
  Design_Table.User_S := Database.User2;

Where Design_Table is the form being created and Database is the current form.

The problem is that in the Design_Table.Create method, the parameters I'm sending don't exist yet.  What method should I use instead of create, or what else can I do?

later

jorge
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1339006
How about storing the informations in the main form, then you'll always know where they are (not depending on how many MDIClients are created)...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339007
Can't you create the second and third form in the OnShow() of the First form???

Regards,
Viktor Ivanov
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339008
Hi jorge,

don't make my neck bigger then it already is :-). Thanks.

On to your problem ... I still don't have the slightest idea what you really want (Sorry).

As I see in your code, every parameter is put in the new created form like you wanted... or not??

TDesigntable looks like this :

TDesigntable = object ....
 ...
 public
  Current_DB_S ...
  Port_S ...
  Host_S ...
  Password_S ...
  User_S ...
 end;

Now when you create the form, they are empty.
After you created them, you fill them up (like in your code)
Then you call a procedure to set all things in place?
Then you call show...

Correct? Missing here something?

Zif.

 
0
 

Author Comment

by:jconde2
ID: 1339009
What do you mean by:
Then you call a procedure to set all things in place?

I tried a messagedlg with one of the parameters I sent in the onShow method and I get an access violation error.

jorge
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339010
Well, I don't know if you need this procedure, but you can call this procedure so you everything will be done what has to be done. e.g. (very dumb) pass a name to certain parameter, then call the procedure search_name. And then show form. Search_name will search for a name in a database and place all information onto form and when form becomes visible the correct data is shown. This is offcourse a very dumb example, because you also could do this by :

property name: String read fName write SearchName(vName:String);

but if you've to set several parameters, maybe it's better not doing it like above, but using a procedure which will do everything at once after all parameters are set.

Zif.
0
 

Author Comment

by:jconde2
ID: 1339011
Thank you zif, go ahead and post your answer!

jorge
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339012
? jconde2 ? Was this what you were looking for? Euhm? What have I said so it solved your solution? Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339013
... last sentence has to be : What have I said to solve your question? :-) Zif.
0
 

Author Comment

by:jconde2
ID: 1339014
Thank you zif, go ahead and post your answer!

jorge
0
 

Author Comment

by:jconde2
ID: 1339015
I got an Idea from the sentence:

property name: String read fName write SearchName(vName:String);

I'll create a custom form object that accepts the parameters before create!

later

jorge
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339016
Hi jconde2,

I´m a little late in this question, but I think that the cleaner solution is to have a descendant form with a overrided Create (constructor) procedure.
Smth like this:

TMyForm: class(TForm)
.
Constructor Create(AOwner: TComponent; Parameter1, ParameterN: string); override;

.
implementation

Constructor Create(AOwner: TComponent; Parameter1, ParameterN: string);
begin
  inherited Create(AOwner);
  //Do smth with Parameters...
end;

IHTH
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339017
mmm, Itamar looks like a good idea. But what if you don't want always react to these parameters. Anyway, good idea. Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339018
Actually I there  are no parameters by default in the Create procedure of a form...you need to create a seperate procedure works with the parameters and then call it in the Create();override;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339019
Viktornet, well yes, didn't thought on that (that create doesn't has a default one). But then using a procedure which creates the form and calls create itself... then I like my solution better. Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339020
Here is an example.......
type
  TMyForm = class(TForm)
  constructor Create(AOwner : TComponent);override;
  procedure WorkWithParams(Param1 : Integer; Param2 : String);virtual;
   //Virtual so you can override it again if you need to without creating a
   //new class all over again
end;

Constructor TMyForm.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner)
  WorkWithParams({The params});
end;

procedure TMyForm.WorkWithPrams({The params});
begin
  //Do what you want with them
end;

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339021
I think Zif's idea is the easiest one to implement and work with ;)

Regards,
Viktor Ivanov
0
 

Author Comment

by:jconde2
ID: 1339022
Thanks viktor!


0
 

Author Comment

by:jconde2
ID: 1339023
Well, who's going to post an answer??????????????????

Thanks to all of you!   Once again, my project will be on time!

Regards,
Jorge
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339024
No prob :-)

Regards,
Viktor Ivanov
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339025
well jorge, it's up to you... it all depends on what you need to program. Does it stays fixed (I mean do you need always to pass the same parameters) or do you sometimes only need to pass some parameters and then react just on these...
I guess you've enough examples now.
Regards, Zif.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Expert Comment

by:viktornet
ID: 1339026
Guys, why don't you send an answer??? You got the answers right ;)

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339027
Hi all,

this is the compete code:

UNIT1 (This one "calls" the form passing parameters)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
var
  NewForm: TForm2;
begin
  NewForm := TForm2.Create(Application, 'Test message');
  NewForm.Show;
end;

end.


UNIT2 (This one contains the Form "called" with parameters)

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    Constructor Create(AOwner: TComponent; Parameter1: string); virtual;
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

Constructor TForm2.Create(AOwner: TComponent; Parameter1: string);
begin
  inherited Create(AOwner);
  ShowMessage(Parameter1);
end;

end.

Notice the virtual declaration instead of override. (I shoud have tested before ;)))

IHTH
0
 

Author Comment

by:jconde2
ID: 1339028
Go ahead vik, zif.....you're the two that helped me the most!

Shame I can't split points!

jorge
0
 

Author Comment

by:jconde2
ID: 1339029
Go ahead vik, zif.....you're the two that helped me the most!

Shame I can't split points!

jorge
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339030
I think jconde2 should say smth before we submit an answer, right ?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339031
Well Zif??? Wanna get 'em?

//Vik
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339032
yup, agree, but I'm up to my bed, have to get up at 6 and oh my look at the time already... I'll hear from you tomorrow or should I say later on the day?
0
 

Author Comment

by:jconde2
ID: 1339033
Guess so!

Good night and thank you zif

jorge
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339034
Hi all,

I don´t see the difficulty in my solution, but go ahead...
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339035
euhm, agree was meant on : I think jconde2 should say smth before we submit an answer, right ?

Zif.
0
 

Author Comment

by:jconde2
ID: 1339036
Guess so!

Good night and thank you zif

jorge
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339037
OK, Bye all....sleep tight,....This conversation becam as long as  novel ;-)

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339038
Zif answer it so it gets closed ;-)
0
 

Author Comment

by:jconde2
ID: 1339039
Since Zif, Vik and Itamar helped me a lot, please do help me out again!

In your personal opinnion, who deserves the points???

Your comments will be very appreciated!

P.S.  (Itamar and Vik gave me Source examples!)

jorge
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339040
ZIF
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339041
Haven't you decided yet??? Zif is almost sleeping ;) Right zif?

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339042
Hey, guys I'm getting outta here, and you decide who's gonna get the points ;) I think this is fair, right?

Regards,
Viktor Ivanov
0
 

Author Comment

by:jconde2
ID: 1339043
Viktornet, Itamar, Zifnab:

Roll the dice and take your shot.
The 3 of you helped me out alot, and if I could, I'd split the points in 3.  

Since that's not the case, shoot!!!!!!!!!

The first one in will get an A.

thanx again!

jorge
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339044

I myself ;) Itamar (sincerely, cause your question talk about passing parameters when creating forms AND I think this is the best OO approach for the problem. I´m not caring with the points, I just would like to show my point-of-view)
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339045
Hey !

E-E administration people can share the points. I did it myself sometime.
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339046
Post a last comment authorizing E-E people to do so and I´ll take care of it.

It´s early in my place...
0
 
LVL 4

Expert Comment

by:itamar
ID: 1339047
Post a last comment authorizing E-E people to do so and I´ll take care of it.

It´s early in my place...
0
 

Author Comment

by:jconde2
ID: 1339048
Fine with me itamar!
Let's do it!

jorge
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339049
Delete the question and send three new questions with the same number of points for three of us...until you see each of us answered one any of them you accept the answers ...

//vik
0
 

Author Comment

by:jconde2
ID: 1339050
It might sound stupid, but how do I delete the question???

all the options I get are
 increase points
 comment to add
 email notification

jorge

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339051
If someone has answered already the Q and you rejeted than that wouldn;t be possible...I don't see the histpry right now so I can't see the rest of the page....
0
 

Author Comment

by:jconde2
ID: 1339052
Please split the points in 3 and grade zifnab, itamar and viktornet with an A respectively.

thanx
jconde2
0
 

Author Comment

by:jconde2
ID: 1339053
Im out!!!

See you all tomorrow!

jorge
0
 
LVL 7

Accepted Solution

by:
linda101698 earned 150 total points
ID: 1339054
jconde2 wants to split the points between three of you.  I'm posting what looks to me to be the final solution so it can be saved.  I'll 150 points to his account which he can use to post questions for the three experts who helped come up with the final solution.  Thanks to all for the GREAT cooperation on this question.

Linda Gardner
Customer Service @ Experts Exchange

     this is the compete code:

     UNIT1 (This one "calls" the form passing parameters)

     unit Unit1;

     interface

     uses
       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
     Dialogs,
       StdCtrls;

     type
       TForm1 = class(TForm)
         Button1: TButton;
         procedure Button1Click(Sender: TObject);
       private
         { Private declarations }
       public
         { Public declarations }
       end;

     var
       Form1: TForm1;

     implementation

     {$R *.DFM}

     uses Unit2;

     procedure TForm1.Button1Click(Sender: TObject);
     var
       NewForm: TForm2;
     begin
       NewForm := TForm2.Create(Application, 'Test message');
       NewForm.Show;
     end;

     end.


     UNIT2 (This one contains the Form "called" with parameters)

     unit Unit2;

     interface

     uses
       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
     Dialogs;

     type
       TForm2 = class(TForm)
       private
         { Private declarations }
       public
         { Public declarations }
         Constructor Create(AOwner: TComponent; Parameter1: string); virtual;
       end;

     var
       Form2: TForm2;

     implementation

     {$R *.DFM}

     Constructor TForm2.Create(AOwner: TComponent; Parameter1: string);
     begin
       inherited Create(AOwner);
       ShowMessage(Parameter1);
     end;

     end.

     Notice the virtual declaration instead of override. (I shoud have tested before
     ;)))

     IHTH
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

21 Experts available now in Live!

Get 1:1 Help Now