• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

Is there any function that it could return me the datatype name of the field in string?

Hy

I use delphi 5 and I'd like to know if there is a function that can return the datetype of my field in string that I could display in a memoedit.

thanks
Alex
0
hidrau
Asked:
hidrau
  • 3
  • 2
1 Solution
 
8080_DiverCommented:
Are you refering to a column in a database, a field in a data file, or what?

Usually there is a way to get the information from a database, assuming you have sufficient permissions to allow you to do so.

As for the Data File, that sort of depends on the data file and the manner in which you are accessing it.  

Other than that, the general IT answer, as always, is going to be, "It depends."
0
 
hidrauAuthor Commented:
When I open a query in an adoquery and I load the columns I want to display in memoedit all the fields name e its datatype:

something like this:

field = product  datatype = ftstring size = 30

the fieldname and size I was able to inform, but datatype not.

The only way I found is that:

  if Qexcel.FieldByName(AFieldName).DataType = ftDateTime Then str :=   'ftDateTime '
  if Qexcel.FieldByName(AFieldName).DataType = ftFloat   Then str := 'ftFloat'

I need to compare with exited datatypes

0
 
hidrauAuthor Commented:
Hi,

I got it :))

this was what I would like

function TFListCotImporta.TipoField(campo: String): String;
const
  cmp : array[0..37] of string = ('ftUnknown', 'ftString', 'ftSmallint', 'ftInteger', 'ftWord', 'ftBoolean', 'ftFloat', 'ftCurrency', 'ftBCD', 'ftDate', 'ftTime', 'ftDateTime', 'ftBytes',
                           'ftVarBytes', 'ftAutoInc', 'ftBlob', 'ftMemo', 'ftGraphic', 'ftFmtMemo', 'ftParadoxOle', 'ftDBaseOle', 'ftTypedBinary', 'ftCursor', 'ftFixedChar', 'ftWideString',
                           'ftLargeint', 'ftADT', 'ftArray', 'ftReference', 'ftDataSet', 'ftOraBlob', 'ftOraClob', 'ftVariant', 'ftInterface', 'ftIDispatch', 'ftGuid', 'ftTimeStamp', 'ftFMTBcd');

var
  x : variant;
begin
  x := TFieldType(Adoquery.FieldByName(campo).DataType);
  showMessage(cmp[StrToInt(x)])
end;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
epasquierCommented:
you can use RTTI information to get the string equivalent of the values in an enum type declaration

1) Add TypInfo unit in uses

2) use GetEnumName function to retrieve the constant name (used in code) corresponding to a value (enumerated, so in fact an integer) of a certain type

3) for the above, you use TypeInfo function to get a pointer on RTTI information of a given type declaration

Delphi is wonderful :o)

Here, a full example listing in a memo all the TFieldType constants strings
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
Uses TypInfo,DB;

procedure TForm1.FormCreate(Sender: TObject);
var
 FT:TFieldType;
begin
 for FT := Low(TFieldType) to High(TFieldType) do
  Memo.Lines.Add(GetEnumName(TypeInfo(TFieldType),Integer(FT)));
end;

end.

Open in new window

0
 
epasquierCommented:
I forgot to mention that this technique of course works with ALL enumerated types, even your own, and does not require that you manually maintain another table of string constants for each and everyone of those enums types where you would need to get their value to string equivalent

Delphi do it for you. Which is precisely why I said Delphi is wonderful :o).
Did I said how great Delphi's RTTI (Run-Time Type Information) system is ?
0
 
hidrauAuthor Commented:
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now