Class loses properties after method call

For my case the parameter passed ByVal as reference type is totally okay as I want to alter the original item.

That means you can change the values of the passed array or the properties of the passed object instance in the method…

But assigning a brand new array to the passed parameter or values to an object instance to the parameter variable will have no effect outside of that method.

What is passed ByVal for objects and arrays is a reference to the object, not the object itself… But you do have write access to and can change the object’s properties.

-Karen

Ok, I think now we all understand the difference between ByRef and ByVal ;-).
But whether ByRef or ByVal … the identifier property should not be lost.

I suggest that you apply a breakpoint in the Constructor, and in the Set method for Identifier.
(VB’s ‘watch … when variable changes’ was a great tool for this stuff.
A computed property is the next best)

Your screenshots do show something that looks incorrect.
The question is… how does Identifier become empty?
The breakpoints may show you when it occurs… either due to a new instance being created, or some code changing the value of identifier.

1 Like

I already tried this but the Constructor never gets called between.
And even if it would be called then there should be a new Identifier and not an empty one.
As the mIdentifier is ReadOnly (via Computed Property) the only code which CAN change the value of mIdentifier is the Constructor.

Not so. (I refuse to use the ‘A’ word here… :> )

Any code in the class’ methods can amend mIdentifier
For example if you had a different computed property called Flibble, and in the set method of that property you issued
mIdentifier = “”
by mistake.
A quick search for mIdentifier globally would reveal that kind of thing.
I don’t expect you will find it, but it’s one way the property could go blank.

1 Like

Nothing else is changing mIdentifier.

Just an observation, but the mTest property seems to be mirroring the mIdentifier value, but I don’t see anywhere in your code where that’s being set.

The mTest was a test where I also set a GUID.
It was set in the Constructor of the class and has a different value.
I wanted to see if the name of the property “Identifier” or anything else with the property was the problem.
But the mTest was also cleared after calling the method.

OK, just wanted to be sure there wasn’t something we were missing with that.

I could solve the problem now by removing the Super class “Rect” of the BaseRect.
In the BaseRect I’m holding now a property mRect As Rect where I’m doing all my stuff with the rect.
Nevertheless it would be interesting to know what caused the original problem.
Why properties of a class are cleared after calling a method with the class as a parameter.

Yeah, I’d be interested in seeing the full code. Theoretically, it should never happen. It almost seems like Xojo is copying the class instance and calling Rect.Constructor without calling the subclass Constructor, which I would definitely consider a bug.

I can send you the project if you want (privately).
Just PM me.

Done.

I guess the order is not properly done.

Public Sub Constructor()

  // Calling the overridden superclass constructor. Setup the basic object.
  Super.Constructor

  mIdentifier = GetUniqueIdentifier(False) // do my post initialization things

End Sub
1 Like

That shouldn’t be the problem as upon inspecting (see the first post), the Identifier is set after Constructing.

This means nothing without a test.

He’s showing us the test. The two images in the first post. It’s set, the object is passed to another method, then it’s no longer set.

He said via PM:

By recreating the issue I found out that typecasting the class before calling “AddField” also solves the problem.

So it sounds like something funky is happening with his casting from one object type to another. I suspect that he’s casting it to an object that isn’t a subclass of his Rect subclass (but is a subclass of Rect), then casting it back causes the value to be lost.

Please, set the proper order and let’s see what happens.

If the problem persists, a basic test isolating the behavior would be great for research.

Same result.