Public Variables

Dave_B_C used Ask the Experts™
I have defined some public variables but when I use them in a called procedure in another .pas file, this fails to compile, saying they are not declared? If I declare them in the lower level module it compiles but the data isn't there? Is there something subtle regarding the declaration/use of public variables in Delphi that I'm missing..?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004
your public vars must be in the interface-part of the unit and not in a type-declaration, just like

var Form1 : TForm1;

the unit where you will use this vars,
should have the unit, where the public vars resides,
in its uses clause

uses TheUnitWhereTheVarsAreDeclared;

maybe you show, what you have done

meikl ;-)
Mohammed NasmanSoftware Developer


  if you declare the variable in the var above implementation, you need to include this unit in each unit that will use that variable

 if you declare the variable in the public section of the class, refer to it using the class name. variable
Mohammed NasmanSoftware Developer

oppps too late :(


Thank you, I was missing the uses clause..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial