[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing settings byRef


On Wed, 3 Jun 2026 at 18:05, Karl Reinl <karl.reinl@xxxxxxxxxx> wrote:

> Salut Benoît,
>
> sorry, but I don’t understand the difference between calling
> fDialogColor and fDialogFile. Why can settings be passed to fDialogFile
> but not to the other two?
> (see attached project)
> --
> Amicalement
> Charlie
>

You need to better understand how to use Byref and also when (or not) you
might need it.

For starters as the wiki states to use Byref it must be used at both ends.
Ie, you use ByRef in the class methods as you have in the Run functions,
but you must also use it in the calling command

The calling command should look more like this DialogFont.Run(ByRef Me.cfg,
"FIDE", "", True)

But i do not think you have to use ByRef at all for your needs here.
Passing the Settings object as an argument should work as expected as you
read the object to write to it's members. (I hope that makes sense)

Consider this ...
Public myNumber As Integer
Public myArray As New String[]

Public Sub PassVariable(ByRef Writable As Boolean)  ' ByRef is needed here
AND in the calling command.

  Writable += 10

End

Public Sub PassObject(Obj As String[])  ' Objects are accessed (read) and
can be manipulated.  only a direct write to the object is not possible.

  Obj.Add("A New Item")

End

Public Sub Main()

  PassVariable(ByRef myNumber)  ' here ByRef is needed to write the value
back to the myNumber variable. Note "ByRef" is in the calling command and
also in the method

  PassObject(myArray)  ' As An object myArray can be manipulated without
using ByRef

End

I think in your program passing a Settings object should not need to use
ByRef.

Someone else might be able to explain the exact reason for this difference
and where you do or do not need ByRef.

As to why it is only failing with some of your classes i could not say.
sorry.

Respects
BruceS

Follow-Ups:
Re: passing settings byRefBruce Steers <bsteers4@xxxxxxxxx>
Re: passing settings byRefKarl Reinl <karl.reinl@xxxxxxxxxx>
References:
passing settings byRefKarl Reinl <karl.reinl@xxxxxxxxxx>