[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: passing settings byRef
[Thread Prev] | [Thread Next]
[Date Prev] | [Date Next]
- Subject: Re: passing settings byRef
- From: Karl Reinl <karl.reinl@xxxxxxxxxx>
- Reply-to: karl.reinl@xxxxxxxxxx
- Date: Thu, 04 Jun 2026 00:23:47 +0200
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Am Mittwoch, dem 03.06.2026 um 22:21 +0100 schrieb Bruce Steers:
>
>
> 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
>
Oh, man, that code comes from gambas1, was ported to gambas2 and the to
gambas3.
As the programme is rarely used, the errors may not have been noticed
for a year or two. They are always down to changes in Gambas 3 itself;
I always use the very latest versions. Thanks for the tip – by omitting
the `ByRef`, it’s working again.
What’s baffling, of course, is that it works sometimes and not others,
and that no errors were reported during compilation, not even during
the two passes.
--
Amicalement
Charlie
| passing settings byRef | Karl Reinl <karl.reinl@xxxxxxxxxx> |
| Re: passing settings byRef | Bruce Steers <bsteers4@xxxxxxxxx> |