Browse Source

* Transform currency

Michaël Van Canneyt 5 months ago
parent
commit
827b95af79
1 changed files with 14 additions and 3 deletions
  1. 14 3
      packages/rtl/src/typinfo.pas

+ 14 - 3
packages/rtl/src/typinfo.pas

@@ -1072,6 +1072,15 @@ begin
   SetJSValueProp(Instance,PropInfo,Value);
   SetJSValueProp(Instance,PropInfo,Value);
 end;
 end;
 
 
+Function TransFormRawValue(aValue : JSValue; const PropInfo :TTypeInfo) : JSValue;
+
+begin
+  if isNumber(aValue) and (PropInfo=System.TypeInfo(Currency)) then
+    Result:=Double(aValue)*10000
+  else
+    Result:=aValue;
+end;
+
 procedure SetJSValueProp(Instance: TJSObject;
 procedure SetJSValueProp(Instance: TJSObject;
   const PropInfo: TTypeMemberProperty; Value: JSValue);
   const PropInfo: TTypeMemberProperty; Value: JSValue);
 type
 type
@@ -1079,18 +1088,20 @@ type
   TSetterWithIndex = procedure(Index, Value: JSValue) of object;
   TSetterWithIndex = procedure(Index, Value: JSValue) of object;
 var
 var
   sk: TSetterKind;
   sk: TSetterKind;
+  lValue : JSValue;
 begin
 begin
+  lValue:=TransFormRawValue(Value,PropInfo.TypeInfo);
   sk:=GetPropSetterKind(PropInfo);
   sk:=GetPropSetterKind(PropInfo);
   case sk of
   case sk of
     skNone:
     skNone:
       raise EPropertyError.CreateFmt(SCantWritePropertyS, [PropInfo.Name]);
       raise EPropertyError.CreateFmt(SCantWritePropertyS, [PropInfo.Name]);
     skField:
     skField:
-      Instance[PropInfo.Setter]:=Value;
+      Instance[PropInfo.Setter]:=lValue;
     skProcedure:
     skProcedure:
       if (pfHasIndex and PropInfo.Flags)>0 then
       if (pfHasIndex and PropInfo.Flags)>0 then
-        TSetterWithIndex(Instance[PropInfo.Setter])(PropInfo.Index,Value)
+        TSetterWithIndex(Instance[PropInfo.Setter])(PropInfo.Index,lValue)
       else
       else
-        TSetter(Instance[PropInfo.Setter])(Value);
+        TSetter(Instance[PropInfo.Setter])(lValue);
     skProcedureWithParams:
     skProcedureWithParams:
       raise EPropertyError.CreateFmt(SIndexedPropertyNeedsParams, [PropInfo.Name]);
       raise EPropertyError.CreateFmt(SIndexedPropertyNeedsParams, [PropInfo.Name]);
   end;
   end;