Link to home
Start Free TrialLog in
Avatar of jconde2
jconde2

asked on

Passing Parameters trough Forms.

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.
Avatar of Edo082297
Edo082297

Hi jconde2

  What exactly do you want to do?

Edo


Avatar of jconde2

ASKER

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
Avatar of jconde2

ASKER

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
Avatar of jconde2

ASKER

Adjusted points to 100
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.
Avatar of jconde2

ASKER

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
Avatar of jconde2

ASKER

Adjusted points to 101
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.
Avatar of jconde2

ASKER

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
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)...
Can't you create the second and third form in the OnShow() of the First form???

Regards,
Viktor Ivanov
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.

 
Avatar of jconde2

ASKER

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
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.
Avatar of jconde2

ASKER

Thank you zif, go ahead and post your answer!

jorge
? jconde2 ? Was this what you were looking for? Euhm? What have I said so it solved your solution? Zif.
... last sentence has to be : What have I said to solve your question? :-) Zif.
Avatar of jconde2

ASKER

Thank you zif, go ahead and post your answer!

jorge
Avatar of jconde2

ASKER

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
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
mmm, Itamar looks like a good idea. But what if you don't want always react to these parameters. Anyway, good idea. Zif.
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;
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.
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
I think Zif's idea is the easiest one to implement and work with ;)

Regards,
Viktor Ivanov
Avatar of jconde2

ASKER

Thanks viktor!


Avatar of jconde2

ASKER

Well, who's going to post an answer??????????????????

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

Regards,
Jorge
No prob :-)

Regards,
Viktor Ivanov
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.
Guys, why don't you send an answer??? You got the answers right ;)

Regards,
Viktor Ivanov
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
Avatar of jconde2

ASKER

Go ahead vik, zif.....you're the two that helped me the most!

Shame I can't split points!

jorge
Avatar of jconde2

ASKER

Go ahead vik, zif.....you're the two that helped me the most!

Shame I can't split points!

jorge
I think jconde2 should say smth before we submit an answer, right ?
Well Zif??? Wanna get 'em?

//Vik
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?
Avatar of jconde2

ASKER

Guess so!

Good night and thank you zif

jorge
Hi all,

I don´t see the difficulty in my solution, but go ahead...
euhm, agree was meant on : I think jconde2 should say smth before we submit an answer, right ?

Zif.
Avatar of jconde2

ASKER

Guess so!

Good night and thank you zif

jorge
OK, Bye all....sleep tight,....This conversation becam as long as  novel ;-)

Regards,
Viktor Ivanov
Zif answer it so it gets closed ;-)
Avatar of jconde2

ASKER

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
Haven't you decided yet??? Zif is almost sleeping ;) Right zif?

Regards,
Viktor Ivanov
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
Avatar of jconde2

ASKER

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

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)
Hey !

E-E administration people can share the points. I did it myself sometime.
Post a last comment authorizing E-E people to do so and I´ll take care of it.

It´s early in my place...
Post a last comment authorizing E-E people to do so and I´ll take care of it.

It´s early in my place...
Avatar of jconde2

ASKER

Fine with me itamar!
Let's do it!

jorge
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
Avatar of jconde2

ASKER

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

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....
Avatar of jconde2

ASKER

Please split the points in 3 and grade zifnab, itamar and viktornet with an A respectively.

thanx
jconde2
Avatar of jconde2

ASKER

Im out!!!

See you all tomorrow!

jorge
ASKER CERTIFIED SOLUTION
Avatar of linda101698
linda101698

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial