Pointers in Xojo

Is there any tutorials or examples for pointers. Even one from Xojo’s built-in examples. What is the purpose of them and what makes them useful?

Thanks

For the most part you don’t have to worry about pointers.
These become important (or at least understanding them becomes important) in regards to

  1. Declares … for passing object references back and forth
  2. Objects… see other forum topics about comparing objects, assigning objects etc…

Obj2=Obj1 ’ creates another pointer to the SAME object, not a new instance

[quote=55758:@Dave S]For the most part you don’t have to worry about pointers.
These become important (or at least understanding them becomes important) in regards to

  1. Declares … for passing object references back and forth
  2. Objects… see other forum topics about comparing objects, assigning objects etc…

Obj2=Obj1 ’ creates another pointer to the SAME object, not a new instance[/quote]
I think I know some stuff about pointers. I believe I use them all the time for comparing to nil or comparing to another object but how are pointers used with brackets next to the name of the class, for example myClass(2), I do not know if 2 could be a valid value but I would get a expected Ptr but got myClass. I probably do not get what is happening but I am reading somebody else’s code here.

myClass(mtag).Parent = me

Will this code just be pointing to an instance of that class using its tag?

Thanks

me is a POINTER, yes. and refers to the current object (be it a window or a control or a class [see also SELF])
your example is setting the PARENT (also a pointer) to “point” to the object/class that is “me”

as in my previous response… the is not creating a new instance… just a pointer

(mtag) is NOT a pointer… it is an ARRAY index

[quote=55769:@Dave S]me is a POINTER, yes. and refers to the current object (be it a window or a control or a class [see also SELF])
your example is setting the PARENT (also a pointer) to “point” to the object/class that is “me”

as in my previous response… the is not creating a new instance… just a pointer

(mtag) is NOT a pointer… it is an ARRAY index[/quote]
But myClass is not an array? Thanks

myClass() is an array.

Yes it is

[quote=55773:@Dave S]’

Yes it is[/quote]
When I right click and click Go To myClass. It does not have ‘()’ to show that it is an array. Does this have something to do with tags and do they make arrays? Thanks

myClass() is an array of type myClass. The class itself wouldn’t be defined as myClass(), it would be plain myClass. Does that make sense?

Ah so you can give arrays the same name as the class?

Yes, but I wouldn’t recommend it because that can become confusing. Names that explain the use are more useful. Also autocomplete can be effected and not work as expected if you use the same names for arrays and classes.

No. What you are probably seeing is CASTING, not an array reference.

That is probably the answer I was looking for. Thanks. What does casting involve then?

Suppose you have 2 classes, Class1 and Class2. Class2 is a subclass of Class1. And suppose Class2 has a property named Parent. If you have a variable of type Class1, it can hold an object of Class2, but it can’t access the Parent property (because Class1 doesn’t have that property). But if you know for sure that the object currently pointed to is in fact a Class2, you can CAST the variable to Class2 temporarily so you can access the additional properties and methods of a Class2 object.

dim c1 as Class1
c1 = new Class2
Class2(c1).Parent = foo

Casting is done by using the class name as if it were a method and passing it the variable to be cast to that class.

Note that none of the above pertains to the Ptr variable type. It is a memory pointer in the more traditional sense.