You are not logged in.
Pages: 1
Hi Arnaud,
today I noticed, that published Currency properties of TSQLRecord descendants aren't serialized properly in TSQLRecord.GetJSONValues:
procedure TSQLRecord.GetJSONValues(W: TJSONWriter);
begin
...
sftCurrency:
W.AddCurr64(Fields[i]^.GetInt64Value(self)); // NOTE: Take a look at GetInt64Value...
...
end;
function TPropInfo.GetInt64Value(Instance: TObject): Int64;
begin
if (Instance<>nil) and (@self<>nil) then
// NOTE: The Kind of a Currency is tkFloat but here is no handling for it!
case PropType^^.Kind of
tkInteger,tkEnumeration,tkSet,{$ifdef FPC}tkBool,{$endif}tkClass:
result := GetOrdProp(Instance,pointer(@self));
tkInt64:
result := GetInt64Prop(Instance,pointer(@self));
else result := 0;
end else
result := 0;
end;
with my quick fix it works well again:
procedure TSQLRecord.GetJSONValues(W: TJSONWriter);
begin
...
sftCurrency:
W.AddCurr64(GetInt64Prop(self, Fields[i]));
...
end;
If you need more info, lets me know and I try to create a small test case...
Best regards!
Offline
I made a code review around similar possible issues, and fixed some potential breaks.
See http://synopse.info/fossil/info/effdec39f4
Nice catch! Thanks!
Offline
Thank you for the fast bug fix!
I'm looking forward to the new 1.13
P.S.: I sent (for a couple weeks) a personal message through this forum. Did you received it?
Offline
hi..
I Created new form inherited from TRecordEditForm (part of the framework),
but with Currency Field Type, i can only type just one digit numerical value, but i can type "00000"...
what is the problem?
note:
i use the MainDemo from the framework..
Offline
There may be an issue in the SQLite3UIEdit.pas.
At first, I don't see any problem: the currency type is handled properly (field value is set as currency, then retrieve from an extended conversion).
Perhaps the TSynLabeledEdit defined in SQLite3UI.pas has some problems with a currency value.
I'll check this, but I need to write a simple program to reproduce it first.
Or perhaps you've one at hand?
Offline
I try to trace the code of TSynLabeldEdit.
i think the problem is on MaxValue property, there set to 100 on constructor.
but i don't know how to set it dinamically depending on Kind:TSynLabeledEditKind property.
Offline
so, what sould to be corection? because it checked on the keypress event.
if IsValid(TempString,Temp) and (Temp>MaxValue) then begin
Key := #0;
Beep;
end;
Offline
Check this out:
http://synopse.info/fossil/info/6f2a76894f
There was some dubious code in several units.
Offline
thanks for the quick fix..
Offline
See http://synopse.info/forum/viewtopic.php?id=345 for a compilation issue.
Offline
TSynLabeledEdit.IsValid doesn't work for me with sleCurrency Kind.
...
sleCurrency: begin
val(Txt,resDouble,err);
if err<>0 then exit;
// ToValue := Currency(resDouble); //this is not work as expected
ToValue := FloatToCurr(resDouble); // i try this, and so far, its work
end;
...
Offline
yes, it's working great. thanks.
Offline
Fixed by http://synopse.info/fossil/info/58715d90b8
Thanks for the report.
Offline
thank you.
BTW, what is the shortage when i use FloatToCurr(resDouble)?
Offline
FloatToCurr() just check the input value range, then assign it to currency.
Our fix consists in using an explicit temporary currency variable, then assign this currency variable to the variant.
Most of the time, currency(resDouble) does the conversion, but it appears that when assigning to a variant, an explicit temporary currency variable is needed.
Weird code generation, I guess, from the compiler point of view.
Offline
ok. thank you for explanation.
Offline
Pages: 1