Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-10

Custom dataset help request: ftCurrency/ftDateTime returns weird data

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Hi all,

I'm writing a custom dataset that represents a list of bank transactions: [1]

When showing a currency field (the Amount field in the transaction object in the code), I get NaN.
Likewise, I get invalid results from a date field (Bookdate in the transaction object)
AFAIU, I can just store the data the way I want but obviously I'm missing something.

The relevant code:
function TTransactionDataset.GetFieldData(Field: TField; Buffer:
Pointer): boolean;
...
  Result := true;
  case Field.FieldName of
    'HashID': StrPLCopy(Buffer, FTransactionList[FCurrentRecord].HashID,
Field.Size);
    'BookDate': TDateTime(Buffer^) :=
FTransactionList[FCurrentRecord].BookDate;
    'Amount': Currency(Buffer^) := FTransactionList[FCurrentRecord].Amount;

FTransactionList is the list with the underlying objects. FCurrentRecord is the current record number.

Suggestions welcome.

Thanks,
Reinier

[1] https://bitbucket.org/reiniero/smalltools/src
directory
BankConvert
file
transactiondataset.pas

Reply by email

Marco van de Voort
to Reinier Olislagers

In our previous episode, Reinier Olislagers said:

Show quoted text 13 lines
missing something. The relevant code: function TTransactionDataset.GetFieldData(Field: TField; Buffer: Pointer): boolean; ... Result := true; case Field.FieldName of 'HashID': StrPLCopy(Buffer, FTransactionList[FCurrentRecord].HashID, Field.Size); 'BookDate': TDateTime(Buffer^) := FTransactionList[FCurrentRecord].BookDate; 'Amount': Currency(Buffer^) := FTransactionList[FCurrentRecord].Amount;

In surprise that it compiles. If buffer is an (untyped) pointer, buffer^ is a byte afaik (just sizeof() it). You cast that byte to currency and then use it as lvalue?

Maybe I miss some weird FPC ability there, and the currency cast makes it take more bytes, but I would expect

pcurrency(buffer)^:=

Reply by email

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote
In surprise that it compiles. If buffer is an (untyped) pointer, buffer^ is a byte afaik

No, it's "untyped" (void). Just like an untyped var/out parameter, which you can also cast to anything and assign things to.

(just sizeof() it).

That will return 0.

You cast that byte to currency and then use it as lvalue?

That is no problem.

Jonas

Reply by email

Reinier Olislagers
to Marco van de Voort: In our previous episode, Reinier Olislagers said: In surprise that it compiles. If buffer…
Marco van de Voort wrote
In our previous episode, Reinier Olislagers said: > 'BookDate': TDateTime(Buffer^) := > FTransactionList[FCurrentRecord].BookDate; > 'Amount': Currency(Buffer^) := FTransactionList[FCurrentRecord].Amount;

<snip>

Maybe I miss some weird FPC ability there, and the currency cast makes it take more bytes, but I would expect pcurrency(buffer)^:=

Thanks, but using that (and similar change for the TDateTime) gives the same results ;(

Reply by email

Unknown author
Reinier Olislagers wrote
Thanks, but using that (and similar change for the TDateTime) gives the same results ;(

perhaps the problem is further back in the code where that data is written to the destination?? i've goofed many many many times and forgotten to use the caret where necessary so i ended up writing the pointer value to a file or stream instead of the data the pointer points to which was what i was really after...

Reply by email