In a ClientDataSearch using Lookup, we're told that to determine if Lookup found an entry is to check whether the returned variant is null (VarIsNull).
This appear to NOT be correct if the field we want to examine is a Boolean.
In a ClientDataSet, I have these fields:
ID (ftInteger)
Last (ftString)
Mark (ftBoolean)
I want to see if an entry for a given ID has Mark as true or false.
var
id: integer;
V: Variant;
begin
id := 5;
V := DM.PeopleCDS.Lookup('ID', id, 'Mark');
found := NOT VarIsNull(V);
Yes, the VarIsNull will correctly be FALSE if the record is NOT found. BUT ... it will also be FALSE, if the record IS found but the returned Boolean value is FALSE.
Here is test code to search for all the IDs from 1 to 12, first looking for the Last field, and then 1 through 12 looking for the Mark field. Some of the entries have Mark true and some false, and some entries have Last showing a name and other entries have Last as blank.
var
id: integer;
V: Variant;
found: Boolean;
begin
Memo.Lines.Add('Lookup ID for a ftBoolean field');
for id := 1 to 12 do
begin
V := DM.PeopleCDS.Lookup('ID', id, 'Mark');
found := NOT VarIsNull(V);
Memo.Lines.Add(' ID ' + IntToStr(id) + ' found? ' + BoolToStr(found));
end;
Memo.Lines.Add('Lookup ID for a ftString field');
for ix := 1 to 12 do
begin
V := DM.PeopleCDS.Lookup('ID', id, 'Last');
found := NOT VarIsNull(V);
Memo.Lines.Add(' ID ' + IntToStr(id) + ' found? ' + BoolToStr(found));
end;
end;
And here are the logged results. Note that
- when return the values of the Last field, Lookup's V isn't null for any of the entries (meaning it found them all), even if the Last field is blank.
- but when searching with a request for the Mark field, the V IS null (supposedly meaning entry not found) even if the record does exist but the Mark field is false!
Lookup ID for a ftString field
ID 1 found? -1
ID 2 found? -1
ID 3 found? -1
ID 4 found? -1
ID 5 found? -1
ID 6 found? -1
ID 7 found? -1
ID 8 found? -1
ID 9 found? -1
ID 10 found? -1
ID 11 found? -1
ID 12 found? -1
Lookup ID for a ftBoolean field
ID 1 found? 0
ID 2 found? 0
ID 3 found? -1
ID 4 found? -1
ID 5 found? -1
ID 6 found? 0
ID 7 found? 0
ID 8 found? 0
ID 9 found? 0
ID 10 found? 0
ID 11 found? 0
ID 12 found? 0
Is there a way to determine if the record actually is found or not?
Thanks in advance! Kevin