#1 2011-04-18 16:11:57

WladiD
Member
From: Germany
Registered: 2010-10-27
Posts: 40

Problem with Currency properties

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

#2 2011-04-18 17:35:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

I made a code review around similar possible issues, and fixed some potential breaks.
See http://synopse.info/fossil/info/effdec39f4

Nice catch! Thanks!
smile

Offline

#3 2011-04-18 19:40:09

WladiD
Member
From: Germany
Registered: 2010-10-27
Posts: 40

Re: Problem with Currency properties

Thank you for the fast bug fix!

I'm looking forward to the new 1.13 smile

P.S.: I sent (for a couple weeks) a personal message through this forum. Did you received it?

Offline

#4 2011-06-13 12:45:23

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

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

#5 2011-06-14 11:23:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

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

#6 2011-06-14 12:18:20

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

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

#7 2011-06-14 14:34:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

Setting the MaxValue to 100 is a bug, I think.

There should be no maximum value by default, only if a corresponding validation rule is set for this field.

Offline

#8 2011-06-14 16:33:53

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

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

#9 2011-06-15 06:01:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

Check this out:
http://synopse.info/fossil/info/6f2a76894f

There was some dubious code in several units.

Offline

#10 2011-06-15 09:25:26

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

thanks for the quick fix..

Offline

#11 2011-06-15 12:00:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

See http://synopse.info/forum/viewtopic.php?id=345 for a compilation issue.

Offline

#12 2013-02-04 14:34:12

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

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

#13 2013-02-04 15:23:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

Is this working?

var tmpCurr: currency;
...
    sleCurrency: begin
      val(Txt,resDouble,err);
      if err<>0 then exit;
      tmpCur := resDouble;
      ToValue := tmpCur;

Offline

#14 2013-02-04 15:43:00

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

yes, it's working great. thanks.

Offline

#15 2013-02-04 15:53:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

Fixed by http://synopse.info/fossil/info/58715d90b8

Thanks for the report.

Offline

#16 2013-02-05 07:19:30

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

thank you.
BTW, what is the shortage when i use FloatToCurr(resDouble)?

Offline

#17 2013-02-05 08:00:09

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem with Currency properties

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

#18 2013-02-05 08:43:08

coblongpamor
Member
From: Bali-Indonesia
Registered: 2010-11-07
Posts: 130
Website

Re: Problem with Currency properties

ok. thank you for explanation.

Offline

Board footer

Powered by FluxBB