Board index » delphi » How to show TField.DataSize and Tfield.DataType???

How to show TField.DataSize and Tfield.DataType???

Greetings.

How can I set the field.datasize and field.datatype to a string value so
that I can show it on a StringGrid on the form. I'm using elphi 3.0.

Thanks.Hoping to hear from you guys soon.
Here is a snippet of the code I'm trying to implement.

     t := Form1.Table1.Fields[i].DataType;
     StringGrid1.Cells[1,i] := (t)asString;
     w.AsString := Form1.Table1.Fields[i].DataSize;
    StringGrid1.Cells[2,i+1] := Form1.Table1.Fields[i].DataSize;
     StringGrid1.Cells[2,i+1] := w.AsString;

 

Re:How to show TField.DataSize and Tfield.DataType???


{
type TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime, ftBytes,
ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo, ftParadoxOle,
ftDBaseOle, ftTypedBinary, ftCursor);

Quote
}

var Tp:String;
 with StringGrid1,  Form1.Table1.Fields[i] do
       begin
             case datatype of
                ftString:Cells[1,i]:='String';
                ftInteger:Cells[1,i]:='Integer';
                ftBoolean:Cells[1,i]:='Boolean'
                {and so on......}
              end;
            Cells[2,i]:=inttostr(Datasize);
      end;
Quote
Ganesan wrote in message <01bce5e8$4ca84200$0d00a8c0@ganespc>...
>     t := Form1.Table1.Fields[i].DataType;
>     StringGrid1.Cells[1,i] := (t)asString;
>     w.AsString := Form1.Table1.Fields[i].DataSize;
>    StringGrid1.Cells[2,i+1] := Form1.Table1.Fields[i].DataSize;
>     StringGrid1.Cells[2,i+1] := w.AsString;

Re:How to show TField.DataSize and Tfield.DataType???


Hello Ganesan,

As far as I know you'll have to write a case statement to convert
Delphi's TFieldType to a string.  Something like...

Function FieldTypeToStr(t : TFieldType) : String;
Begin
  Case t of
    ftUnknown : Result := 'Unknown';
       ...
  End;
End;

With the data size property something like:
w := IntToStr(Form1.Table1.Fields[I].DataSize);

Hope this helps,
Mike

Other Threads