[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: passing settings byRef
[Thread Prev] | [Thread Next]
- Subject: Re: passing settings byRef
- From: BB <adamnt42@xxxxxxxxx>
- Date: Sun, 7 Jun 2026 18:17:21 +0930
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On 4/6/26 7:53 am, Karl Reinl wrote:
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 <mailto: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 CharlieYou 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 commandThe 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 EndPublic 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 methodPassObject(myArray) ' As An object myArray can be manipulated without using ByRefEndI 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 BruceSOh, 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
I don't think that the compiler knows or even thinks about how the call stack is going to be used at runtime. It is only looking at whether it can construct a JUMP thingo with a valid parameter stack and whether the return stack can be processed (maybe not even that).
b
| passing settings byRef | Karl Reinl <karl.reinl@xxxxxxxxxx> |
| Re: passing settings byRef | Bruce Steers <bsteers4@xxxxxxxxx> |
| Re: passing settings byRef | Karl Reinl <karl.reinl@xxxxxxxxxx> |