Dont' use Datasize. This is the internal size of the field in the buffer.
Use Sizeof( ) the actual datatype being read eg Float, String
-----Original Message-----
From: [EMAIL PROTECTED]
[SMTP:[EMAIL PROTECTED]]
Sent: Friday, July 09, 1999 5:01 PM
To: Multiple recipients of list delphi
Subject: [DUG]: Error copying TDateTime using TField.GetData
Hi,
I'm loading the contents of a database table into memory in an array of
pointers. I'm using the TField's DataSize property to allocate the memory
for each pointer and then using the GetData method of the TField to dump
the contents from the database into the memory pointed to by one of the
elements in the array. It looks like this:
for i := 0 to dbRowsCount - 1 do begin
... stuff
for j := 0 to dbColCount - 1 do begin
// get the memory for the cell - The array layout is
Cols[x].Row[y]
GetMem(MyArray[j].Data[i],AQuery.Fields.Fields[j].DataSize);
// read the data into the cell
AQuery.Fields.Fields[j].GetData(FTableData[j].Data[i]);
end;
end;
Simple enough and has been working fine ...... until I tried reading in a
field of type ftDateTime. When I do that, I end up with a HUGE number that
won't convert to a TDateTime (ie. can't pass it to the DateTimeToStr
function without raising an invalid floating point operation exception.
I have checked the value of AQuery.Fields.Fields[j].AsString at the time of
copying and it definitely contains a valid date that I can cast to a double
and pass to DateTimeToStr without any problem.
Does anyone know if the TField stores the 8 bytes it takes for a TDateTime
(basically a double) in an unusual fashion? All the other data I copy over
using this method comes across fine.
Thanks for any help.
Phil.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
application/ms-tnef