tbdata is a field of TForm1 so the code that uses it must have an
instance of TForm1 to access tbdata.
So the code that uses it needs to have:
FormInstance.tbData.First;
while not FormInstance.tbData.eof do
etc.
John Bird wrote:
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
begin:vcard
fn:Phil Middlemiss
n:Middlemiss;Phil
org:Vision Software, MTS Ltd
email;internet:[EMAIL PROTECTED]
title:Project Leader
tel;work:+64 7 3480001
tel;cell:+64 27 4592648
x-mozilla-html:TRUE
url:http://www.tumonz.co.nz
version:2.1
end:vcard
_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi