Board index » delphi » Locate not locating and findkey not finding

Locate not locating and findkey not finding

I am using Locate but it doesn't seem to work:

The following code snippets all fail to find an existing record
and try to append a record with the same primary key, with a
resultant key violation. I have tried deleting all the indices
(including the primary .px) and rebuilding them to no avail. The
primary key in A_Book is Address No so I know FindKey is the
preferred option but nothing seems to work. I have found this to
be a problem before in some other smaller tables and resorted to
filtering and checking the record count but that can't be right
- What am I doing wrong?

This seems a pretty vital function which cannot afford to be
unreliable.

Quote

vTemp:Variant;

vTemp:=dm.SourceSourceRef.Value;
   dm.A_Book.First;
    if not dm.A_book.Locate('AddressNo',vTemp,[]) then begin    
      dm.A_Book.Append;
      dm.A_BookAddressNo.Value := dm.SourceSourceRef.Value;
    end else dm.A_Book.Edit;
.. field content changes.

Quote

I have also tried
Quote
>> sTemp:=dm.SourceSourceRef.AsString;

if not dm.A_book.Locate('AddressNo',sTemp,[])      then begin
..

Quote

and
Quote
>> sTemp:=dm.SourceSourceRef.AsString;

if not
dm.A_book.Locate('AddressNo',dm.SourceSourceRef.AsString,[])    
..

Quote

and

Quote
>> if not dm.A_book.FindKey([dm.SourceSourceRef.Value]) >>

and
Quote
>> nTemp:=dm.SourceSourceRef.Value;

if not dm.A_book.FindKey([nTemp]) >>

and

Quote
>> sTemp:=dm.SourceSourceRef.AsString;

if not dm.A_book.FindKey([sTemp]) >>

and

Quote
>> if not dm.A_book.FindKey([dm.SourceSourceRef.AsString])>>

Pat Bell

Pat Bell

 

Re:Locate not locating and findkey not finding


Opening and closing A_Book was not all I had been doing - I also
set a filter which I did not clear. Simple and stupid that's me
<g>

Pat Bell

Other Threads