Proper translation from MS data type to TFieldType

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
hiwrz
Posts: 1
Joined: Fri 11 Mar 2022 11:23

Proper translation from MS data type to TFieldType

Post by hiwrz » Fri 11 Mar 2022 11:31

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

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Proper translation from MS data type to TFieldType

Post by MaximG » Thu 17 Mar 2022 15:40

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;

Post Reply