2

I need to maintain an array of objects references and pass each item to functions to manage it. I know I can do something like that:

Dim arrObjs As MyObject[]  
Dim refObj As MyObject

arrObjs.Add(New MyObject) 'First reference to the Object.  
refObj=arrObjs[0]         'Second reference to the same Object.  

I think that is right, but reading Gambas Object Model documentation, I read that when passing an argument by reference (ByRef) there is no pointer involved. Instead, the value is copied inside the function and then copied again outside the function after function finish. Example:

Sub manageObject(ByRef refObj As MyObject)  
    .....  
End  

Calling time:

manageObject(ByRef arrObjs[0])  

How can I manage true references to Objects inside procedures? Is there something like that?

Dim obj As New MyObject        'Correct  
Dim objInstance As MyObject    'Correct  
Dim refObj as Pointer          'Correct  

refObj=varPtr(obj)             'NOT Correct, but i would like  
objInstance=Object@(refObj)    'NOT Correct, but i would like  
Icepickle
  • 12,689
  • 3
  • 34
  • 48
jalonsor
  • 21
  • 1
  • Please try and use code blocks and inline code blocks when you write code check out the [formatting doc](http://stackoverflow.com/editing-help#comment-formatting) – Thatkookooguy Aug 11 '16 at 09:24

1 Answers1

0

Once you have object(s) created with NEW you can use methods and read/write properties of this object:

arrObjs[0].method()   
arrObjs[1].property=value

See the object data type definition and an example with an array of objects:
The array of objects can be shared simply by a public array.
You can write the following when using handles or references:

hinstance = arrObjs[0]

and then:

hinstance.method()
Peter Bauer
  • 284
  • 2
  • 7