Page 1 of 1

Proper translation from MS data type to TFieldType

Posted: Fri 11 Mar 2022 11:31
by hiwrz
Hi,

is it possible that I get a demo on how to get TFieldType from MS data type name as string? I am on SDAC 7.3, Delphi Seattle.

For example I've got string "int" and want to get "ftInteger".

Code: Select all

select name from sys.types where system_type_id = 56
Thanks in advance

Re: Proper translation from MS data type to TFieldType

Posted: Thu 17 Mar 2022 15:40
by MaximG
To get the TField data type as a string, you can use the following approaches:

1)

Code: Select all

uses
   TypInfo;
...
var
  FieldNameStr: String;
begin
  ...
  FieldNameStr := GetEnumName(TypeInfo(TFieldType), Ord(MSQuery.FieldByName('your field name').DataType)));
  ...
end;
2)

Code: Select all

uses
   Data.DB;
...
var
  FieldNameStr: String;
begin
  ...
  FieldNameStr := FieldTypeNames[MSQuery.FieldByName('your field name').DataType];
  ...
end;