Board index » delphi » Locate problem

Locate problem


2004-10-12 10:06:52 PM
delphi139
The following code does not bring back the correct 'siteno' .
I am presuming the locate makes the record with (Site_Ref = 'location') as
the current record
then sitenum should be the number in the 'Site_Num'. ?????
Any help appreciated.
Steve W.
var
i : integer;
regnumber, temp, directory, location, siteno, number : string;
begin
with Datamodule2.Table_Ticket_Reports do
begin
try
First;
while not eof do
begin
directory :=
'P:\Data_Files\project\Server_tables\licenses\' ;
location :=
datamodule2.Table_Ticket_Reports['Location_Code'];
DataModule2.Table_sites.locate('Site_Ref',(location),
[loPartialKey]);
siteno := datamodule2.Table_Sites['Site_Num'];
showmessage(location);
showmessage(siteno);
siteno := siteno + '.jpg';
siteno := directory + siteno ;
datamodule4.ppReport1.ArchiveFileName :=
'p:\Data_Files\project\Server_Tables\reports\DVLA_Request.rtm';
datamodule4.ppReport1.DataPipeline := datamodule4.ppDBPipeline4;
datamodule4.ppImage2.Picture.LoadFromFile(siteno);
datamodule4.ppReport1.Print;
next;
end;
finally end;
 
 

Re:Locate problem

Try defining Location as a Variant and remove the parentheses around
Location in the Locate call.
If you are going to post code please format it properly including
proper indenting. It is very hard to read the code you post.
--
Bill (TeamB)
TeamB cannot answer questions received via email
 

Re:Locate problem

"Steve Warburton" wrote
Quote
The following code does not bring back the correct 'siteno' .
Steve, Just a couple of comments:
The formatting of your code made it hard to read.
Your "try ... finally end" construct does nothing.
Why don't you use the AsXXXX properties of the
fields to access the data? Rgds, JohnH
 

Re:Locate problem

Do you have a simple example?
Point taken about the code. I tend to write like a mad man when struggling,
then format once I know what I am doing. I will endeavour to do this before
posting.
"John Herbster" <herb-sci1_AT_sbcglobal.net>writes
Quote

"Steve Warburton" wrote
>The following code does not bring back the correct 'siteno' .

Steve, Just a couple of comments:
The formatting of your code made it hard to read.
Your "try ... finally end" construct does nothing.
Why don't you use the AsXXXX properties of the
fields to access the data? Rgds, JohnH


 

Re:Locate problem

"Steve Warburton" wrote
Quote
Do you have a simple example?
Steve, Bill Todd and other DB experts may not agree,
but I strongly prefer to use persistent fields where I can
and if the fields are persistent, then use
loc := DM2.Table_Ticket_ReportsLocation_Code.AsString;
instead of this
loc := DM2.Table_Ticket_Reports['Location_Code'];
because
(1) I like to assume that I know what kind of variables
I am dealing with at compile time and have the compiler
slap my hand if I make a mistake; and two
(2) I like the field lookup to be once by the compiler rather
than have it done each time that it is use at run-time.
Further, I like to move the code that uses the datamodule
objects over into the datamodule itself, unless there is
really good reason for doing otherwise.
Regards, JohnH
 

Re:Locate problem

In addition, using the .AsXXX properties instead of getting the field
value as a variant avoids the always popular "invalid variant type
conversion" error that occurs when the field is null and you try to
assign the value to a non-variant variable.
--
Bill (TeamB)
TeamB cannot answer questions received via email