cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
Tran Thanh Lo
Booster

How to set a string for a cell in array values of GDL object?

Spoiler
 

I get and set a value in array values like this.

 

if ((*memo.params)[i].name == (GS::UniString)"matrix_area")
		{
			API_AddParType* pAddPar = &(*memo.params)[i];

			GS::uchar_t** arrHdl = reinterpret_cast<GS::uchar_t**>(pAddPar->value.array);

			(*arrHdl)[0] = 'f';
		}

 

But I can only set it to the uchar_t value. Can I set it a string value?
Can you answer for me? Thank you very much.

1 Solution

Accepted Solutions
DGSketcher
Legend

In GDL land an array may only contain one data type e.g. number or string, they can't be mixed. Not sure if that is what you are trying to do?

Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)

Go to post

3 Replies 3
DGSketcher
Legend

In GDL land an array may only contain one data type e.g. number or string, they can't be mixed. Not sure if that is what you are trying to do?

Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)
Tran Thanh Lo
Booster

@DGSketcher wrote:

In GDL land an array may only contain one data type e.g. number or string, they can't be mixed. Not sure if that is what you are trying to do?


Yes, I see. Thank you very much.

You need to use something like GS::ucscpy to copy a whole string (instead of a single character) into a uchar_t pointer. And the handle needs to be appropriately sized!

Here's some (untested) sample code:

GS::Array<GS::UniString> stringsToCopy{ "foo", "barbar" };

// assuming we have a one dimensional parameter array of strings
auto& currentParam = (*memo.params)[i];
if (currentParam.dim1 != 1) { return; }

currentParam.dim1 = usedZoneCats.GetSize ();
currentParam.dim2 = 1;

GS::USize totalLength = 0;
for (const auto str : stringsToCopy) {
	// +1 because the "\0" string delimiter is not counted in GetLength () function
	totalLength += str.GetLength () + 1;
}

currentParam.value.array = BMReallocHandle (currentParam.value.array,
	totalLength * sizeof (GS::uchar_t), REALLOC_FULLCLEAR, 0);
auto attrArray = reinterpret_cast<GS::uchar_t*>(*currentParam.value.array);
GS::USize strStart = 0;
for (Int32 j = 0; j < currentParam.dim1; ++j) {
	GS::ucscpy (attrArray + strStart, stringsToCopy[j].ToUStr ());
	strStart += stringsToCopy[j].GetLength () + 1;
}
Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!