Hello,
How to found the field with the index and not with the fieldname ?
Thank for your help.
TOraQuery and field index
Re: TOraQuery and field index
Oups sorry I forget to do login.Anonymous wrote:Hello,
How to found the field with the index and not with the fieldname ?
Thank for your help.

Finnaly I write a new function. I have buy ODAC with source code, and my new fonction is based to your code.
I have write other fonction, FieldAsString,FieldAsFloat,FieldAsDate.
If you are interested I send you my new fonctions.
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;
If you are interested I send you my new fonctions.