Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

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
Avatar of 8080_Diver
8080_Diver
Flag of United States of America image

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."
Avatar of hidrau

ASKER

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

Avatar of hidrau

ASKER

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;
ASKER CERTIFIED SOLUTION
Avatar of Emmanuel PASQUIER
Emmanuel PASQUIER
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ?
Avatar of hidrau

ASKER

thanks