Macros : ByVal doesn't work with parameters in a class object modul ...

Hi,

I'm using Libreoffice :

Version: 5.2.7.2
Build ID: 1:5.2.7-1
Threads CPU : 2; Version de l'OS :Linux 4.12; UI Render : par défaut; VCL : gtk3;
Locale : fr-FR (fr_FR.UTF-8); Calc: group

Below is a complet macro to manage Vectors of variants (With french coments) . I've got a problem with unitary test (Cf. Sub Main) because call to procedure 'v.Ajouter(duolet)' use always passage by reference instead of a passage by value (ByVal) ! For all that, I delicately manage a passage by value in my function...

I tested with a call to New operator in order to build specifics instances at each call, like this :

  duolet = new __TDuolet
  duolet.key = "MONTAGNE"
  duolet.Item = 3
  v.Ajouter(duolet)

And it's fine, the duolet variable is a new one instance. But I don't want the caller do all this stuff. I would like easier way to do ...

I'm asking myself if it's a specific bug to my LibreOffice versin, or with Variants and Struct type (__TDuolet) ?

What do you think about that ? What can I do to copy by val the parameter into my function v.Ajouter(duolet) ?

Think you for your help...

Patrick

PS: Macro is below, it's a draft ...

Hi Patrick,

Below is a complet macro to manage Vectors of variants (With french
coments) . I've got a problem with unitary test (Cf. Sub Main) because
call to procedure 'v.Ajouter(duolet)' use always passage by reference
instead of a passage by value (ByVal) ! For all that, I delicately
manage a passage by value in my function...

I tested with a call to New operator in order to build specifics
instances at each call, like this :

    duolet = new __TDuolet
    duolet.key = "MONTAGNE"
    duolet.Item = 3
    v.Ajouter(duolet)

And it's fine, the duolet variable is a new one instance. But I don't
want the caller do all this stuff. I would like easier way to do ...

This
     v.Ajouter(ByVal duolet)
won't do. The ByVal specifier is only present at the declaration level, not the calling one.

You could just add a CreateDuolet() function to create the Duolets, like this :

Function CreateDuolet(ByRef pKey As String, pItem As Variant) As __TDuolet

  Dim MyDuolet As __TDuolet

  MyDuolet.key = pKey
  MyDuolet.item = pItem

  CreateDuolet = MyDuolet

End Function

(note : this function is not a class member)

Then, the caller has just to specify:

duolet = CreateDuolet("MONTAGNE", 3)
v.Ajouter(duolet)

or you might also simply call
v.Ajouter(CreateDuolet("MONTAGNE", 3))

BTW, I've noticed some glitches elsewhere, eg: in the _Expend() method, you've declared isPresserved as Optional but never test for its presence or not in the method body. This might lead to strange results, don't you think?
[BTW, BTW, shouldn't the method be called "_Expand" instead of "_Expend"?]

HTH,