Board index » delphi » Record not found error on Locate

Record not found error on Locate

We have a number of TCheckBox components that we wish set the Checked
property, depending on the presence of an associated code in a detail table.
The check box references an array of codes which is then used in a Locate
statement on the detail table

type
  TSpecCodes = Array[1..NumSpecBoxes] of string;
const
  fSpecCodes: TSpecCodes = ('uv', 'uw', 'ua', 'tn', 'tp', 'ts', 'ul', 'tt',
'tv', 'tj', etc

then we use the following code to update all the CheckBoxes

for i:=1 to NumSpecBoxes do begin
  fComponent := FindComponent('cbSpec'+intToStr(i));
  if fComponent<>nil then
    with (fComponent as TCheckBox) do
      Checked := dmHomes1.GetSpecialism(fSpecCodes[i]);
  end;

function TDMHomes1.GetSpecialism(ACode: string): boolean;
begin
Result := tbSpecialisms_.Locate('SPECIALISM_CODE', ACode, []);
end;

The first two calls to GetSpecialisms (codes 'uv' and 'uw') work fine,
returning False. however, the third call (code 'ua') raises an Exception
'Record not found' after the call to Locate.  If the value of ACode is
changed to 'uw' on this call using Evaluate/Modify then the exception is not
raised.

What is going on?  Locate should return false if it cannot find a record,
not raise an exception.

Environment is Windows 95, Delphi 3.02, BDE 5.00, Interbase v 5.1.1.680

--
Roger Graham
DesignKey Ltd (UK)

 

Re:Record not found error on Locate


Try a Refresh on the table before Locate.  There seems to be a BDE
problem with locate on table with mixed case keys.  Refresh usually
resolves the problem.  
Quote
Roger Graham wrote:

> We have a number of TCheckBox components that we wish set the Checked
> property, depending on the presence of an associated code in a detail table.
> The check box references an array of codes which is then used in a Locate
> statement on the detail table

> type
>   TSpecCodes = Array[1..NumSpecBoxes] of string;
> const
>   fSpecCodes: TSpecCodes = ('uv', 'uw', 'ua', 'tn', 'tp', 'ts', 'ul', 'tt',
> 'tv', 'tj', etc

> then we use the following code to update all the CheckBoxes

> for i:=1 to NumSpecBoxes do begin
>   fComponent := FindComponent('cbSpec'+intToStr(i));
>   if fComponent<>nil then
>     with (fComponent as TCheckBox) do
>       Checked := dmHomes1.GetSpecialism(fSpecCodes[i]);
>   end;

> function TDMHomes1.GetSpecialism(ACode: string): boolean;
> begin
> Result := tbSpecialisms_.Locate('SPECIALISM_CODE', ACode, []);
> end;

> The first two calls to GetSpecialisms (codes 'uv' and 'uw') work fine,
> returning False. however, the third call (code 'ua') raises an Exception
> 'Record not found' after the call to Locate.  If the value of ACode is
> changed to 'uw' on this call using Evaluate/Modify then the exception is not
> raised.

> What is going on?  Locate should return false if it cannot find a record,
> not raise an exception.

> Environment is Windows 95, Delphi 3.02, BDE 5.00, Interbase v 5.1.1.680

> --
> Roger Graham
> DesignKey Ltd (UK)

Re:Record not found error on Locate


We tried using a TQuery

qrySpecialisms_.SQL =
'SELECT SPECIALISM_CODE FROM SPECIALISMS
 WHERE ORG_ID = :ORG_ID AND SPECIALISM_CODE = :SPECIALISM_CODE'

function TDMHomes1.GetSpecialism(ACode: string): boolean;
begin
with qrySpecialisms_ do begin
  ParamByName('ORG_ID').asInteger := tbOrganisations_ORG_ID.asInteger;
  ParamByName('SPECIALISM_CODE').asString := ACode;
  Open;
  Result := RecordCount>0;
  end;
end;

This did not work, it did not raise an exception as in the TTable but it did
returned False for all codes, even those present in the Specialisms table.

However, what did work, was to use a TQuery linked to the master table on
ORG_ID and use a locate

qrySpecialisms_.SQL =
'SELECT SPECIALISM_CODE FROM SPECIALISMS
 WHERE ORG_ID = :ORG_ID

qrySpecialisms_.DataSource := dsOrganisations;

function TDMHomes1.GetSpecialism(ACode: string): boolean;
Result := qrySpecialisms_.Locate('SPECIALISM_CODE', ACode, []);
end;

Why the first two methods did not work, I do not know.  But now it works, I
ain't goin' to fix it.

Roger Graham
DesignKey Ltd (UK)

Re:Record not found error on Locate


Quote
>Try a Refresh on the table before Locate.  There seems to be a BDE
>problem with locate on table with mixed case keys.  Refresh usually
>resolves the problem.

I am also having the same error returned when trying to do a Locate on an
empty Detail TTable.  The key of the master is Integer (ORG_ID) and the
second key field of the detail is a string field.  Is this what you mean by
mixed case keys?

Surely doing a refresh is a considerable overhead on a client-server
database (or any database for that matter), particularly if its a large
dataset.

Roger Graham
DesignKey Ltd (UK)

Re:Record not found error on Locate


Are these exceptions raised in the IDE, but not when you run the .exe
outside of the IDE?  If so, you may have found a VCL peculiarity.
Sometimes, a locate or query that returns no rows will raise an
excpetion in the VCL, which is eaten.  If you have "Break on Exception"
turned on, you'll see it; if not, you won't.  We have found at least two
places in the VCL with a construct like:
  try
    {do something}
  except
  end;
that we have traced to these errors.  

By "mixed-case", I meant keys that contain lower-case codes and,
sometimes, special characters.  We have found cases where these cause
duplicated grid rows and locate problems when using TTable.  Usually a
Refresh will correct the problem; it is not expensive.

Quote
Roger Graham wrote:

> >Try a Refresh on the table before Locate.  There seems to be a BDE
> >problem with locate on table with mixed case keys.  Refresh usually
> >resolves the problem.

> I am also having the same error returned when trying to do a Locate on an
> empty Detail TTable.  The key of the master is Integer (ORG_ID) and the
> second key field of the detail is a string field.  Is this what you mean by
> mixed case keys?

> Surely doing a refresh is a considerable overhead on a client-server
> database (or any database for that matter), particularly if its a large
> dataset.

> Roger Graham
> DesignKey Ltd (UK)

Re:Record not found error on Locate


I apologize for my bad english.

I have the same problem and I'm sorry to tell you that the Refresh doesn't
works always!
Also I think that's not a good way put Refresh method anywhere to avoid the
problem!

This is a big problem , has someone posted  it to the Inprise ?

Bye, A. Laperuta.

Quote
Nick Pavlina wrote in message <36A77116.1...@scruznet.com>...
>Are these exceptions raised in the IDE, but not when you run the .exe
>outside of the IDE?  If so, you may have found a VCL peculiarity.
>Sometimes, a locate or query that returns no rows will raise an
>excpetion in the VCL, which is eaten.  If you have "Break on Exception"
>turned on, you'll see it; if not, you won't.  We have found at least two
>places in the VCL with a construct like:
>  try
>    {do something}
>  except
>  end;
>that we have traced to these errors.

>By "mixed-case", I meant keys that contain lower-case codes and,
>sometimes, special characters.  We have found cases where these cause
>duplicated grid rows and locate problems when using TTable.  Usually a
>Refresh will correct the problem; it is not expensive.

>Roger Graham wrote:

>> >Try a Refresh on the table before Locate.  There seems to be a BDE
>> >problem with locate on table with mixed case keys.  Refresh usually
>> >resolves the problem.

>> I am also having the same error returned when trying to do a Locate on an
>> empty Detail TTable.  The key of the master is Integer (ORG_ID) and the
>> second key field of the detail is a string field.  Is this what you mean
by
>> mixed case keys?

>> Surely doing a refresh is a considerable overhead on a client-server
>> database (or any database for that matter), particularly if its a large
>> dataset.

>> Roger Graham
>> DesignKey Ltd (UK)

Other Threads