Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables from one form to another? 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I know it may be a dumb question.
I have a main form that has all my variables and function.

I have a button on the form that open another form like that:
ProcessF := TProcessF.Create ( Self );
try
if ProcessF.ShowModal = mrOk then
begin
{}
end;
finally
{}
end;

In the processF forma, i would like to use a couple of variables and one function declared in the main form. Is that possible or do I need to re enter the function and variables?
I do have a uses syntax that calls the main form inside ProcessF.

Thanks.
Pierre
 
Think of your project in a hierarchy view. Either create a new unit or pick the lowest level unit. Put all your "global variables" (and functions) there, in the INTERFACE section. For functions, put just a declaration statement. Put the code in the IMPLEMENTATION section. Like this:
Code:
unit MyGlobals;

interface

uses 
  windows, graphics, classes;  //whatever you need...

var
  MyGStr: string;
  MyGInt: integer;

function GlobalFunk(x: integer; s: string): boolean;

implementation

function GlobalFunk(x: integer; s: string): boolean;
begin
  result:= (x > -1) and (s <> '');
  if result then 
    MyGStr:= 'FUNKY'
end;

end.
Any unit or form that has MyGlobals in the uses clause will see them, including the main form and .dpr


Roo
Delphi Rules!
 
ARG! - I forgot to mention, vars from the main form can be passed as parameters to the sub-unit as shown in the example above for vars "x" and "s".

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top