ZQuery.FieldByName(Field).AsString;
function TDataSet.FieldByName(
const FieldName:
string): TField;
begin
Result := FindField(FieldName);
if Result =
nil then DatabaseErrorFmt(SFieldNotFound, [FieldName], Self);
end;
function TDataSet.FindField(
const FieldName:
string): TField;
begin
Result := FFields.FindField(FieldName);
if (Result =
nil)
and ObjectView
then
Result := FieldList.Find(FieldName);
if Result =
nil then
Result := FAggFields.FindField(FieldName);
end;
function TFields.FindField(
const FieldName:
string): TField;
var
I: Integer;
begin
for I := 0
to FList.Count - 1
do
begin
Result := FList.Items[I];
if WideCompareText(Result.FFieldName, FieldName) = 0
then Exit;
end;
Result :=
nil;
end;
function TField.GetAsString:
string;
begin
Result := GetClassDesc;
end;
function TField.GetClassDesc:
string;
var
I, L: Integer;
S:
string;
begin
S := ClassName;
I := 1;
L := Length(S);
if S[1] = '
T'
then
I := 2;
if (L-I >= 5)
and (CompareText(Copy(S, L - 4, 5), '
FIELD') = 0)
then
Dec(L, 5);
FmtStr(Result, '
(%s)', [Copy(S, I, L + 1 - I)]);
if not IsNull
then
Result := AnsiUpperCase(Result);
end;
//////////////////////////////////////
Und hier TFieldDefs
//////////////////////////////////////
TFieldDefs =
class(TDefCollection)
private
FParentDef: TFieldDef;
FHiddenFields: Boolean;
function GetFieldDef(
Index: Integer): TFieldDef;
procedure SetFieldDef(
Index: Integer; Value: TFieldDef);
procedure SetHiddenFields(Value: Boolean);
protected
procedure FieldDefUpdate(Sender: TObject);
procedure ChildDefUpdate(Sender: TObject);
procedure SetItemName(AItem: TCollectionItem);
override;
function GetFieldDefClass: TFieldDefClass;
virtual;
public
constructor Create(AOwner: TPersistent);
virtual;
function AddFieldDef: TFieldDef;
function Find(
const Name:
string): TFieldDef;
procedure Update;
reintroduce;
{ procedure Add kept for compatability - AddFieldDef is the better way }
procedure Add(
const Name:
string; DataType: TFieldType; Size: Integer = 0;
Required: Boolean = False);
property HiddenFields: Boolean
read FHiddenFields
write SetHiddenFields;
property Items[
Index: Integer]: TFieldDef
read GetFieldDef
write SetFieldDef;
default;
property ParentDef: TFieldDef
read FParentDef;
end;