Menu

#1 UibDataSet

open
nobody
None
6
2010-11-01
2010-11-01
avail
No

I need Locate in UibDataSet

function Locate(const KeyFields: string; const KeyValues: variant; Options: TLocateOptions): boolean; override;
...

function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string;
const KeyValues: variant; Options: TLocateOptions): boolean;
var
FieldCount: integer;
Fields: TList;
{$IFDEF UIB_D7}
Bookmark: TBookmarkStr;
{$ELSE}
Bookmark: TBookmark;
{$ENDIF}

function CompareField(Field: TField; Value: variant): boolean;
var
S: string;
begin
if Field.DataType = ftString then
begin
S := Field.AsString;
if (loPartialKey in Options) then
Delete(S, Length(Value) + 1, MaxInt);
if (loCaseInsensitive in Options) then
Result := AnsiCompareText(S, Value) = 0
else
Result := AnsiCompareStr(S, Value) = 0;
end
else
Result := (Field.Value = Value);
end;

function CompareRecord: boolean;
var
I: integer;
begin
if FieldCount = 1 then
Result := CompareField(TField(Fields.First), KeyValues)
else
begin
Result := true;
for I := 0 to FieldCount - 1 do
Result := Result and CompareField(TField(Fields[I]), KeyValues[I]);
end;
end;

begin
Result := false;
with DataSet do
begin
CheckBrowseMode;
if BOF and EOF then
Exit;
end;
Fields := TList.Create;
try
DataSet.GetFieldList(Fields, KeyFields);
FieldCount := Fields.Count;
Result := CompareRecord;
if Result then
Exit;
DataSet.DisableControls;
try
Bookmark := DataSet.Bookmark;
try
with DataSet do
begin
First;
while not EOF do
begin
Result := CompareRecord;
if Result then
Break;
Next;
end;
end;
finally
{$IFDEF UIB_D7}
if not Result and DataSet.BookmarkValid(pchar(Bookmark)) then
{$ELSE}
if not Result and DataSet.BookmarkValid(Bookmark) then
{$ENDIF}
DataSet.Bookmark := Bookmark;
end;
finally
DataSet.EnableControls;
end;
finally
Fields.Free;
end;
end;

function TUIBCustomDataSet.Locate(const KeyFields: string;
const KeyValues: variant; Options: TLocateOptions): boolean;
begin
DoBeforeScroll;
Result := DataSetLocateThrough(Self, KeyFields, KeyValues, Options);
if Result then
begin
DataEvent(deDataSetChange, 0);
DoAfterScroll;
end;
end;

Discussion

  • avail

    avail - 2010-11-01

    uibdataset with locate

     
  • avail

    avail - 2010-11-01
    • priority: 5 --> 9
     
  • avail

    avail - 2010-11-01
    • priority: 9 --> 6
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.