Automation/Safearray

sljslj Member Posts: 6
Hi...

I'm trying to call a function in an automation called ImageMagick. The function has the following signature:

[VARIANT Convert :=] ImageMagick.Convert(VAR SAFEARRAY pArrayVar)

How do I pass the parameter "VAR SAFEARRAY pArrayVar" from C/AL? Which C/AL datatype am I supposed to pass? As far as I can figure from a Visual Basic code sample it is a function, which takes a variable number of arguments of type string.

/Stefan

Comments

  • RobertMoRobertMo Member Posts: 484
    So have you tried to define a variable of Text data type and set its property Dimemsion to value bigger then 1?
    What happend?
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • sljslj Member Posts: 6
    Yes, I have tried that... :(

    The following code...

    CREATE(ImageMagick);
    TextArray[1] := 'logo:';
    TextArray[2] := '-format';
    TextArray[3] := '10,20,30';
    TextArray[4] := 'logo.jpg';
    ImageMagick.Convert(TextArray);

    ...produces a runtime error: "The array dimensions must be identical".

    ImageMagick is the automation and TextArray is a text array with dimensions 4. I have tried different array dimensions.

    The following VB code seems to be working:

    Set img = CreateObject("ImageMagickObject.MagickImage.1")
    msgs = img.Convert("logo:","-format","%m,%h,%w","logo.jpg")

    One idea is to pass the array using the Variant datatype, but anyone who knows how I do that? The following code does not work:

    CREATE(ImageMagick);
    TextArray[1] := 'logo:';
    TextArray[2] := '-format';
    TextArray[3] := '10,20,30';
    TextArray[4] := 'logo.jpg';
    VariantVar := TextArray;
    ImageMagick.Convert(VariantVar);

    It produces a runtime error: ":= cannot be performed on arrays. Choose a single array value using an expression such as: MyArray[...]".

    /Stefan
  • RobertMoRobertMo Member Posts: 484
    what if you try:
    ImageMagick.Convert(TextArray[1],TextArray[2],TextArray[3],TextArray[4]);
    

    If not, maybe you can try to find out what is the limit of the array in VB. For sure it is not "that unlimited". There must be some nice big number...
    Write a code in VB and call the function each time with one parm more. (I don't know how exactly should this look like in VB)
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • sljslj Member Posts: 6
    It gives a compilation error:

    A maximum of 1 parameters must be used when calling the function. For example:

    MyFunc( .. , .. , .. )
    ROUND(MyVar)
    ROUND(MyVar,0.05)

    :(

    /Stefan
  • alex123alex123 Member Posts: 6
    slj wrote:
    It gives a compilation error:

    A maximum of 1 parameters must be used when calling the function. For example:

    MyFunc( .. , .. , .. )
    ROUND(MyVar)
    ROUND(MyVar,0.05)

    :(

    /Stefan

    We need to import BMP to jpg or gif in NAvision.
    I have got the same problem with convert function.
    Is anybody knows where is answer? ](*,)
  • gcoellegcoelle Member Posts: 8
    Hi Alex,

    Yes we've had the same problem ...

    The SAFEARRAY is used as a kind of variable argument list. Unfortunately, Navision cannot map SAFEARRAY types to one of its internal variables. (as stated in the Admin Guide)
    We have programmed a tiny OCX, which works like a wrapper to other Automation Controllers. With this, you can invoke ImageMagick with the following Code:
    OW.CreateObjectByName (IM, 'ImageMagickObject.MagickImage.1');
    OW.SetParam (1, 'logo:');
    OW.SetParam (2, 'c:\temp\logo.jpg');
    OW.CallMethod (Val, IM, 'Convert', 2);
    

    See upload section (dbOleWrap) for the first Beta-release of this OCX. Please test and send me your comments.
    In the hope, that it is helpful - Gunter
Sign In or Register to comment.