tbData level is protected as it belongs to class form1. You would need to either make tbData public - although it is probably a visual control so Delphi wont allow you to
Or try using form1.tbData. Probably a better approach would be to put your data access controls in a DataModule which all members are public by default. web: www.softwarex.co.nz blog: http://softwarex-nz.blogspot.com -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Bird Sent: Friday, 10 February 2006 9:58 a.m. To: 'NZ Borland Developers Group - Delphi List' Subject: [DUG]Scope This is my understanding of accessing variables and procedures and functions in other units and forms: Functions and Procedures I found summarised nicely in a post: "From: James Getz <[EMAIL PROTECTED]> Subject: Re: Calling a procedure in another form The answer to your question depends on where you declare the function. If the function is declared as part of the form object, then you would use form.function (it is a method of the form class at that point) to access it. If it's a freestanding function (not part of a class) then you would access it as unit.function." I have also found that if the other unit is in the uses clause, then a freestanding function or procedure does not even need the unit name - the compiler and linker can find it using the uses clause. This is how I use a unit full of library procedures and functions, with just the procedure or function name. Delphi also does this all the time, for example to find FieldbyName is defined in Delphi 2006 hovering over this statement reveals the tip "Declared in DB.TDataSet", and when using FieldbyName no unit prefix is required. Variables - if declared in the interface section of say unit1, and unit2 has a "uses unit1" statement then unit2 can see these global variables in unit1. QUESTION: Now - I have moved some code from one unit to another and it won't compile Unit1 declares in the interface section type TForm1 = class(TForm) tbData: TClientDataSet; DataSource1: TDataSource; DBGrid1: TDBGrid; Unit2 declares implementation {$R *.dfm} uses Unit1,Unit3...etc; But statements in unit2 such as tbData.First; while not tbData.eof do begin setfont('arial',8); printtab(tbData.fieldbyname('Field1').asString); printtab(tbData.fieldbyname('Field2').asString); printtab(tbData.fieldbyname('Field3').asString); Are all giving errors about tbdata saying undeclared identifier and won't compile. I am thinking Unit2 should be able to see tbData in Unit1. (I am trying to put some Rave Report code into a separate general printing routine so I can re-use it). John _______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi _______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi
