比如我可以获取某个字段的值。但是是否可以查出该字段的长度呢?
MyQuery.Fields[0].Value; // contains the value of the field
最佳答案
字段大小可以从 Field.Size 获取,如果此值为 0 Size,则它是您使用 Field.Datasize 的固定类型。
简短示例:
uses TypInfo;
Procedure DisplayFieldInfos(DS:TDataset;List:TStrings);
var
i:Integer;
Function GetSize(F:Tfield):Integer;
begin
Result := F.Size;
if Result=0 then Result := F.DataSize;
end;
begin
for I := 0 to DS.FieldCount - 1 do
begin // display Fieldname [Datatype] : Size
List.Add(Format('%s [%s] : %d',
[
DS.Fields[i].FieldName,
GetEnumName(TypeInfo(TFieldType), integer(DS.Fields[i].Datatype)),
GetSize(DS.Fields[i])
]));
end;
end;
procedure TForm6.Button1Click(Sender: TObject);
begin
DisplayFieldInfos(ADS,Memo1.Lines)
end;
关于mysql - 如何获取TADOQuery中字段的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16094766/