How to get FieldLength in Plusin

yzsind

Member²
I have know the way that use "SQL_FieldName" and "SQL_FieldType" to get the fieldname and fieldtype,now I want to know how to get the fieldlength(fieldsize) in PlusIn.
 
Because I want to build a TDataSet and show in a datagrid.
if has the FieldLength Property,I can set the Field Lenth,then the datagrid can automatic set column's width.

this is my code:

function SQLResultToDS(): TCustomClientDataSet;
var
vDS: TCustomClientDataSet;
i: integer;
vFieldType: TFieldType;
begin
vDS := TCustomClientDataSet.Create(nil);
for i := 0 to SQL_FieldCount - 1 do
begin
case SQL_FieldType(i) of
3: vFieldType := ftInteger;
4: vFieldType := ftFloat;
5: vFieldType := ftString;
8: vFieldType := ftInteger;
12: vFieldType := ftDateTime;
24: vFieldType := ftGuid;
else
vFieldType := ftUnknown;
end;
if vFieldType = ftString then
begin
vDS.FieldDefs.Add(SQL_FieldName(i), vFieldType, 40);
end
else
vDS.FieldDefs.Add(SQL_FieldName(i), vFieldType);
end;
vDS.CreateDataSet;
while not SQL_Eof do
begin
vDS.Append;
for i := 0 to SQL_FieldCount - 1 do
begin
if length(string(SQL_Field(i))) > 0 then
vDS.Fields.Value := string(SQL_Field(i));
end;
vDS.UpdateRecord;
SQL_Next;
end;
result := vDS;
end;
 
I see. Well, at the moment this is not possible, but I have added this to the list of enhancement requests. For ftString fields you can now only apply the maximum length, which is 4000 bytes.
 
Back
Top