Hello Nick
1.
Quote:
Can I suggest a locate method with multi-keyvalue to search in the internal buffer of all records just like standard datasets?
It will come handy comparing to writing a for-loop statement when coding.
Unfortunately, there is no Locate method in the TRecordsListEh list.
(May be we will add similar method at the next version)
You can use its next counterpart - FindRecInRecordsList.
Code:
function FindRecInRecordsList(RecList: TRecordsListEh; const KeyFields: string;
const KeyValues: Variant; TryUseIndex: Boolean = True): TMemoryRecordEh;
var
Fields: TList;
I, RecIndex: Integer;
MTIndex: TMTIndexEh;
procedure GetFieldList(List: TList; const FieldNames: string);
var
Pos: Integer;
Field: TMTDataFieldEh;
Len: Integer;
begin
Len := FieldNames.Length;
Pos := 1;
while Pos <= Len do
begin
Field := RecList.DataStruct.FieldByName(ExtractFieldName(FieldNames, Pos));
if Assigned(List) then List.Add(Field);
end;
end;
function CompareRecValues(Rec: TMemoryRecordEh; const VarValues: Variant): Boolean;
var
I: Integer;
begin
if Fields.Count = 0 then
Result := False
else if Fields.Count = 1 then
Result := VarEquals(Rec.Value[TMTDataFieldEh(Fields.First).Index, dvvValueEh], VarValues)
else begin
Result := True;
for I := 0 to Fields.Count - 1 do
Result := Result and VarEquals(Rec.Value[TMTDataFieldEh(Fields[I]).Index, dvvValueEh], VarValues[I]);
end;
end;
begin
Result := nil;
MTIndex := nil;
Fields := TList.Create;
try
GetFieldList(Fields, KeyFields);
if TryUseIndex then
MTIndex := RecList.Indexes.GetIndexForFields(KeyFields);
if MTIndex <> nil then
begin
if MTIndex.FindRecordIndexByKey(KeyValues, RecIndex) then
Result := RecList[RecIndex]
end else
begin
for I := 0 to RecList.Count-1 do
begin
if CompareRecValues(RecList.Rec[i], KeyValues) then
begin
Result := RecList.Rec[i];
Break;
end
end;
end;
finally
Fields.Free;
end;
end;
2.
Quote:
Besides, I am always confused with the 2 properties of MemTableEh.Rec and MemTableEH.RecView, what is the difference between the 2 properties?
--
MemTableEh.Rec points to the current record of TMemoryRecordEh type where the data is stored.
--
MemTableEH.RecView points to the TMemRecViewEh object.
TMemRecViewEh contains a pointer to the data record - Rec: TMemoryRecordEh
And the properties for creating the tree structure of Child nodes.
They are used when MemTableEh is in tree mode.