type
.............
TDataSet = class(TComponent, IProviderSupport)
function GetFieldValue(const FieldName: string): Variant;
procedure SetFieldValue(const FieldName: string; const Value: Variant);
property FieldValues[const FieldName: string]: Variant read GetFieldValue write SetFieldValue; default;
......
end;
function TDataSet.GetFieldValue(const FieldName: string): Variant;
var
I: Integer;
Fields: TList;
begin
if Pos(';', FieldName) <> 0 then
begin
Fields := TList.Create;
try
GetFieldList(Fields, FieldName);
Result := VarArrayCreate([0, Fields.Count - 1], varVariant);
for I := 0 to Fields.Count - 1 do
Result := TField(Fields).Value;
finally
Fields.Free;
end;
end else
Result := FieldByName(FieldName).Value
end;
procedure TDataSet.SetFieldValue(const FieldName: string;
const Value: Variant);
var
I: Integer;
Fields: TList;
begin
if Pos(';', FieldName) <> 0 then
begin
Fields := TList.Create;
try
GetFieldList(Fields, FieldName);
for I := 0 to Fields.Count - 1 do
TField(Fields).Value := Value;
finally
Fields.Free;
end;
end else
FieldByName(FieldName).Value := Value;
end;
这是一个数组属性(ADODataSet都继承自TDataSet,FieldValues是TDataSet的数组属性),实现机制实际上是在一个List里面查找得到的,参看这个属性的读写方法(GetFieldValues和SetFieldValues)的源代码即可得知怎么运作的。