When I have dropdown that is lined to both DataSource and ListSource and if ListSource has records and DataSource field DOES NOT have a value (i.e. database field value is null or null-string) then when a dropdown is displayed then for each dropdown that meets this condition error in "image 1" is prompted.
"image 2" is an example of one of my frames that exhibits this problem.
Not ideal but here is a change I made to the unit "Data.Win.ADODB" that fixed the problem.
- Code: Select all
function TCustomADODataSet.LocateRecord(const KeyFields: string;
const KeyValues: OleVariant; Options: TLocateOptions;
SyncCursor: Boolean): Boolean;
var
Fields: TList<TField>;
Buffer: TRecordBuffer;
I, FieldCount: Integer;
Partial: Boolean;
SortList, FieldExpr, LocateFilter: string;
begin
{2018 04 21 ZSL: TO overcome CGD KeyValues = null}
if KeyValues <> null then
begin
CheckBrowseMode;
UpdateCursorPos;
CursorPosChanged;
Buffer := TRecordBuffer(TempBuffer);
Partial := loPartialKey in Options;
Fields := TList<TField>.Create;
DoBeforeScroll;
try
try
GetFieldList(Fields, KeyFields);
if not Assigned(FLookupCursor) then
FLookupCursor := Recordset.Clone(adLockReadOnly);
if CursorLocation = clUseClient then
begin
for I := 0 to Fields.Count - 1 do
if Pos(' ', TField(Fields[I]).FieldName) > 0 then
SortList := Format('%s[%s],', [SortList, TField(Fields[I]).FieldName]) else
SortList := Format('%s%s,', [SortList, TField(Fields[I]).FieldName]);
SetLength(SortList, Length(SortList)-1);
if FLookupCursor.Sort <> SortList then
FLookupCursor.Sort := SortList;
end;
FLookupCursor.Filter := '';
FFilterBuffer := Buffer;
SetTempState(dsFilter);
try
InitRecord(Buffer);
FieldCount := Fields.Count;
if FieldCount = 1 then
FLookupCursor.Find(GetFilterStr(FieldByName(KeyFields), KeyValues, Partial), 0,
adSearchForward, EmptyParam)
else
begin
for I := 0 to FieldCount - 1 do
begin
FieldExpr := GetFilterStr(Fields[I], KeyValues[I], (Partial and (I = FieldCount-1)));
if LocateFilter <> '' then
LocateFilter := LocateFilter + ' AND ' + FieldExpr else { Do not localize }
LocateFilter := FieldExpr;
end;
FLookupCursor.Filter := LocateFilter;
end;
finally
RestoreState(dsBrowse);
end;
finally
Fields.Free;
end;
Result := not FLookupCursor.EOF;
if Result then
if SyncCursor then
begin
Recordset.Bookmark := FLookupCursor.Bookmark;
if Recordset.EOF or Recordset.BOF then
begin
Result := False;
CursorPosChanged;
end
end
else
{ For lookups, read all field values into the temp buffer }
for I := 0 to Self.Fields.Count - 1 do
if Self.Fields[I].FieldKind = fkData then
PVariantList(PByte(Buffer)+SizeOf(TRecInfo))[Self.Fields[I].Index] := FLookupCursor.Fields[Self.Fields[I].FieldNo-1].Value;
except
Result := False;
end;
end;
end;
Can you please look at fixing this in CGD code. Also, I this this will also be the case whereever CGD uses the Lookp functtion
TIA