# How is the REALGetClassProperty / REALCountClassProperties used

**URL:** <https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819>\
**Category:** Plugins\
**Created:** [March 12, 2023, 10:49pm UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819 "2023-03-12T22:49:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [March 12, 2023, 10:49pm UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/1 "2023-03-12T22:49:59Z")

</div>

Hello

I have for first time been trying REALGetClassProperty / REALCountClassProperties in attempt to speed things up a bit.

But I think I am using it wrong somehow, since I get crash. (Guessing it has something to do with the param, which I was not understanding the use of maybe)

So my question is how is it supposed to be used ?

(see my crash example bellow)

```auto
RBInteger count = REALCountClassProperties(shapeInstance);

OutputDebugStringA("Counted.....");

void* getter;
void* setter;
long param = 0;
REALstring declaration;
size_t numBytes;

for (RBInteger i = 0; i < count; ++i)
{
	OutputDebugStringA("Step in the for loop....."); // We get this

	if (REALGetClassProperty(shapeInstance, (uint32_t)i, &getter, &setter, &param, &declaration)) // We crash here
	{
		const char* declarationData = (const char*)REALGetStringContents(declaration, &numBytes);

		OutputDebugStringA(declarationData);

		if (strcmp(declarationData, "ArcAngle") == 0)
		{
			ArcAngleSetter = (void (*)(REALobject, RBInteger, double))setter;
		}
		else if (strcmp(declarationData, "StartAngle") == 0)
		{
			StartAngleSetter = (void (*)(REALobject, RBInteger, double))setter;
		}

		//REALUnlockString(declaration); // I got this commented out for now but I was not sure if we supposed to unlock here or not.
	}

	OutputDebugStringA("After the if check....."); // We do not come here
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 13, 2023, 6:59am UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/2 "2023-03-13T06:59:51Z")

</div>

For which value of I does it crash?

I have this working in my code:

```auto
void *FindPropertyGetter(REALobject o, const char* propDeclaration, bool WantSetter)
{
	if (o)
	{
		RBInteger propCount = REALCountClassProperties(o);
		DebugMessage("propCount", propCount);
		
		for (RBInteger i = 0; i < propCount; I++)
		{
			void *getter = nil;
			void *setter = nil;
			long param = 0;
			REALstring declaration = nil;
			RBBoolean r = REALGetClassProperty(o, i, &getter, &setter, &param, &declaration);
			FreeLater(declaration);
			
			if (r)
			{
				rbText t(declaration);
				if (strcmp(t.GetUTF8(), propDeclaration) == 0)
				{
					if (WantSetter)
						return setter;
					return getter;
				}
			}
		}

```

and it looks very similar.

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [March 13, 2023, 8:50am UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/3 "2023-03-13T08:50:56Z")

</div>

Hmmmmm yes looks very much the same.

For me it crashes on first call to REALGetClassProperty for instance of ArcShape object.

And it crashes on the call it self to the REALGetClassProperty.

I guess I could try setting the getter and setters to nil, since thats the only diff I see.

Thanks

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [March 13, 2023, 9:03am UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/4 "2023-03-13T09:03:05Z")

</div>

Yes it works !

I set the getter, setter and declaration to nil, before the call and then everything works.

But this means there is feature there that we do not know about…since Xojo is doing something with the parameters as input and not just as output.

And its probably on the declaration REALstring parameter…possibly direct lookup by name ?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 13, 2023, 9:47am UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/5 "2023-03-13T09:47:21Z")

</div>

Strange. Maybe make an issue and reference this thread?

Maybe @William_Yu can look in the code of the framework?

---

<div class="post-metadata">

**Author:** ![William\_Yu](https://forum.xojo.com/user_avatar/forum.xojo.com/william_yu/32/610_2.png) [@William\_Yu](https://forum.xojo.com/u/William_Yu)\
**Post date:** [March 13, 2023, 1:23pm UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/6 "2023-03-13T13:23:43Z")

</div>

Yes, please create an Issues for this, I’m a bit surprised that this function works the way it does. The declaration parameter is definitely the fragile component in this situation.

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [March 13, 2023, 2:19pm UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/7 "2023-03-13T14:19:41Z")

</div>

I also found that the declaration should not be unlocked. But if its unlocked then you eventually crash due to string reference count problem.

(Which contradicts Christians code)

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 13, 2023, 2:36pm UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/8 "2023-03-13T14:36:27Z")

</div>

But that unlock was in the example code I got from William years ago 😉

So maybe a bug?

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [March 13, 2023, 3:04pm UTC](https://forum.xojo.com/t/how-is-the-realgetclassproperty-realcountclassproperties-used/74819/9 "2023-03-13T15:04:19Z")

</div>

Very possibly

I am just reporting my findings from having done extensive tests on the thing today.
