Page 1 of 1

TOraQuery and field index

Posted: Mon 09 May 2005 09:01
by Guest
Hello,
How to found the field with the index and not with the fieldname ?

Thank for your help.

Re: TOraQuery and field index

Posted: Mon 09 May 2005 09:03
by nschmied
Anonymous wrote:Hello,
How to found the field with the index and not with the fieldname ?

Thank for your help.
Oups sorry I forget to do login. :)

Posted: Tue 10 May 2005 10:00
by Alex
Try to use Fields property of Dataset object. For more information pls. see "Fields property (TDataSet)" topic in Delphi help.

Posted: Wed 11 May 2005 08:36
by nschmied
Finnaly I write a new function. I have buy ODAC with source code, and my new fonction is based to your code.

Code: Select all

const
  SInvalidFieldId = 'Field %s does not exist';
  SConvertErrorToDouble = 'Cannot convert field %s to a Float';
  SConvertErrorToInteger = 'Cannot convert field %s to an Integer';
  SConvertErrorToString = 'Cannot convert field %s to a String';
  SConvertErrorToDate = 'Cannot convert field %s to a TDateTime';

TOracleQuery = class(TOraQuery)
...

function TOracleQuery.FieldAsInteger(FieldId: Integer): Integer;
var
  Field: TFieldDesc;
  RecBuf: TRecordBuffer;
  Ptr: IntPtr;
  val : Variant;
begin
  if (FieldId>-1) and (FieldId<Data.FieldCount) Then begin
    Ptr := Marshal.AllocHGlobal(sizeof(IntPtr));
    Marshal.WriteIntPtr(Ptr, nil);
    try
      if GetActiveRecBuf(RecBuf) then begin
        Field := Data.Fields.Items[FieldId];
        if Data.GetNull(Field.FieldNo, RecBuf) then
          Result := 0
        else
          try
            Data.GetFieldAsVariant(Field.FieldNo, RecBuf,val);
            Result := val;
          except
            Result := 0;
            DatabaseErrorFmt(SConvertErrorToInteger,[Field.Name]);
          end;
      end
      else
        Result := 0;
    finally
      Marshal.FreeHGlobal(Ptr);
    end;
  end else
    DatabaseErrorFmt(SInvalidFieldId,[FieldId]);
end;
I have write other fonction, FieldAsString,FieldAsFloat,FieldAsDate.

If you are interested I send you my new fonctions.