Link to home
Start Free TrialLog in
Avatar of Rob Rietow
Rob Rietow

asked on

How do I find the value of a field's datatype

In code below, I have not been able to interrogate the value of query1.fieldbyname(''+vfield+'').datatype.  The value type in the SQL Database is ntext.  When I retrieve the field via the sql statement and trace through the Case statement, my code drops to the end statement without stopping at any of the "ft.."  values.  

  with Query1 do
  begin
    close;
    sql.clear;
    sql.Add('Select '+vfield);
    sql.Add('from '+vTable);
    sql.Add('where code = '+inttostr(vCode));
    open;
      case query1.fieldbyname(''+vField+'').datatype of
        ftString: result := fieldbyname(''+vField+'').AsString;
        ftInteger: result := fieldbyname(''+vField+'').asInteger;
        ftFloat: result := fieldbyname(''+vField+'').asFloat;
        ftBoolean: result := fieldbyname(''+vField+'').asBoolean;
        ftMemo: result := fieldbyname(''+vfield+'').AsString;
        ftBlob: result := fieldbyname(''+vfield+'').AsString;
        ftGraphic: result := fieldbyname(''+vfield+'').AsString;
        ftUnknown: result := fieldbyname(''+vfield+'').AsString;
        ftFmtMemo: result := fieldbyname(''+vfield+'').AsString;
        ftVarBytes: result := fieldbyname(''+vfield+'').AsString;
        ftBytes: result := fieldbyname(''+vfield+'').AsString;
        ftBCD: result := fieldbyname(''+vfield+'').AsString;
        ftParadoxOle: result := fieldbyname(''+vfield+'').AsString;
        ftDBaseOle: result := fieldbyname(''+vfield+'').AsString;
        ftTypedBinary: result := fieldbyname(''+vfield+'').AsString;
        ftWord: result := fieldbyname(''+vfield+'').AsString;
        ftSmallint: result := fieldbyname(''+vfield+'').AsString;
        ftCurrency: result := fieldbyname(''+vfield+'').AsString;
        ftDate: result := fieldbyname(''+vfield+'').AsString;
   end;
end;
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

The list of available field types is e.g. here: http://docwiki.embarcadero.com/Libraries/Sydney/en/Data.DB.TFieldType
ftWideString and ftWideMemo is missing in your list (beside others).

The best you can do is to look at the numeric value of the datatype.
Avatar of Rob Rietow
Rob Rietow

ASKER

How do you find the numeric value of Datatype?

put a breakpoint here

case query1.fieldbyname(''+vField+'').datatype of

then add/watch " query1.fieldbyname(''+vField+'') "
here check what is it and whats the datatype...
Tried that. Inaccessible value.
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia 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