geoffsmith82 / delphi-javascript

Automatically exported from code.google.com/p/delphi-javascript
5 stars 2 forks source link

Issue when function parameter has type Variant #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Delphi XE2.

Let's say we have some global function in Delphi:

class function TSMJSGlobalFunctions._VariantToInt (varVal : variant) : integer;
begin
    Result := Integer (varVal);
end;

This is how from JavaScript we calling this function:

function doF () {
    _Debug ("VariantToInt 100 = " + _VariantToInt ("100"));
}

NOTE: "_Debug" function, just another global function, which showing result in 
some window.

So, when from JavaScript we call "VariantToInt ("100")", in Delphi function 
will be passed value UNASSIGNED, instead actual value equal to "100" (type 
string).

How I fixed it:

In unit "jsintf.pas"
class function TJSClass.JSValToTValue(cx: PJSContext; t: PTypeInfo; vp: jsval; 
RttiType: TRttiType): TValue;

From {
  Result := TValue.Empty;
  case t^.Kind of
}
To {
    Result := TValue.Empty;

    //-=-

    intVarType := t^.Kind;

    if intVarType = tkVariant then
    begin
        case vp.tag of
            JSVAL_TAG_STRING :
                intVarType := tkString;
            JSVAL_TAG_INT32 :
                intVarType := tkInteger;
        end;
    end;

    //-=-

    case intVarType of
}

New variable added:
    intVarType  : System.TypInfo.TTypeKind;

Original issue reported on code.google.com by andre...@diatomenterprises.com on 11 Dec 2013 at 9:11

Attachments:

GoogleCodeExporter commented 8 years ago
Dear Sirs,

Could you include our company logo with note "Special thanks to:" to your 
project home page http://code.google.com/p/delphi-javascript/ ?

Our logo: 
http://diatomenterprises.com/Images/Logos/diatomenterprises-logo-128x47.png
Link to our home page: http://diatomenterprises.com/

Thanks a lot!

With best regads,

Original comment by andre...@diatomenterprises.com on 11 Dec 2013 at 9:17

Attachments:

GoogleCodeExporter commented 8 years ago
Variants are not supported and not plan to add support since this is not that 
simple

Original comment by n.ame...@gmail.com on 11 Dec 2013 at 11:12