- changed status to resolved
Problem with TObjectDataSet Locate method
Hi,
I found the problem with using TObjectDataSet.Locate method. According to: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Using_Locate I expect to Locate allows to move cursor to the first dataset's row matching a specified set of search criteria. For TObjectDataSet.Locate it is not always true. Lets consider following simple dataset:
Id MasterId Value
1 10 abc
2 10 def
3 10 ghi
If the cursor is on the third row then I expect that calling command: DataSet.Locate('MasterId', 10, []) will move the cursor to the first row because first row matches search criteria. But for TObjectDataSet the cursor stays on 3. row. It causes some problems with db-aware controls which expects that Locate will find the first row matching a search criteria. In my case it is details panel of TcxGrid (from DevExpress)
The problem occurs because in DataSetLocateThrough function (which is used in Locate function) one shortcut is made:
Fields := TObjectList{$IFDEF DELPHIXE3_UP}<TField>{$ENDIF}.Create(False);
try
DataSet.GetFieldList(Fields, KeyFields);
FieldCount := Fields.Count;
// this shortcut causes unexpected result for Locate function
Result := CompareRecord;
if Result then
Exit;
// end of the problematic code
DataSet.DisableControls;
try
Bookmark := DataSet.Bookmark;
try
DataSet.First;
while not DataSet.Eof do
begin
Result := CompareRecord;
if Result then
Break;
DataSet.Next;
end;
In the shortcut the function checks the current row matches a search criteria and if matches cursor stays on the current row.
The shortcut speeds up function's excecution but in some cases it causes to unexpected behaviour. I think this shortcut should be removed. Could you consider this, please?
Comments (1)
-
repo owner - Log in to comment
fixed
#396→ <<cset 78e87e842e71>>