<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How set to a text array&amp;amp;#65311;&amp;amp;#65311; in GDL</title>
    <link>https://community.graphisoft.com/t5/GDL/How-set-to-a-text-array-amp-65311-amp-65311/m-p/173889#M5328</link>
    <description>&lt;BLOCKQUOTE&gt;QBai wrote:&lt;BR /&gt;I create a text-type array in GDL-object， I use it in source，but I found that I can‘t add text-type’s value to the text-type array。&lt;BR /&gt;
&lt;BR /&gt;
EX Source：
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;char cTmp[256];
GSHandle handle = params.value.array;

BMKillHandle((GSHandle *) &amp;amp;handle);
handle = BMAllocateHandle(sizeof(GS::uchar_t) * 256, ALLOCATE_CLEAR, NULL );

GS::uchar_t*  pRealValue = (GS::uchar_t *)*handle;

sprintf(cTmp,"HANDRAIL_%d",1);
GS::UniString tmp1("1");
GS::ucscpy(pRealValue, tmp1.ToUStr());
&lt;/PRE&gt;

Who can help me？&lt;BR /&gt;
Whatever the result,thank you for you advice！&lt;/BLOCKQUOTE&gt;

Hi,&lt;BR /&gt;
&lt;BR /&gt;
Here's a sample code from the AC18 Element_Modify.cpp file; it may point you to the right direction:&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;bool ChangeArrayParam (API_ElementMemo		*inMemo, 		// memo of the given library part element
                       const char			*paramName,
					   Int32 				inDim1,			// the new first dimension
					   Int32 				inDim2,			// the new second dimension
					   const GS::uchar_t	*inParVal,		// the new value
					   Int32 				inIndex1,		// first index of the new value
					   Int32 				inIndex2)		// second index of the new value
{
	Int32 n = BMGetHandleSize ((GSHandle) inMemo-&amp;gt;params) / sizeof (API_AddParType);

	if (inIndex1 &amp;gt;= inDim1 || inIndex2 &amp;gt;= inDim2 || inIndex1 &amp;lt; 0 || inIndex2 &amp;lt; 0 || inParVal == NULL)
		return false;
	// Bad parameters

	// searching for an array parameter
	for (Int32 i = 0; i &amp;lt; n; i++) {
		// check if it's an array parameter and the array contains strings
		if ((*inMemo-&amp;gt;params)&lt;I&gt;.typeMod == API_ParArray &amp;amp;&amp;amp;
				((*inMemo-&amp;gt;params)&lt;I&gt;.typeID == APIParT_CString || (*inMemo-&amp;gt;params)&lt;I&gt;.typeID == APIParT_Title) &amp;amp;&amp;amp;
				CHCompareASCII ((*inMemo-&amp;gt;params)&lt;I&gt;.name, paramName) == 0)
		{
			GS::uchar_t **origArrHdl = (GS::uchar_t **) (*inMemo-&amp;gt;params)&lt;I&gt;.value.array;
			Int32 origDim1 = (*inMemo-&amp;gt;params)&lt;I&gt;.dim1;
			Int32 origDim2 = (*inMemo-&amp;gt;params)&lt;I&gt;.dim2;

			// calculating new size of the array
			Int32 newSize = 0;
			Int32 lastPos = 0;
			for (Int32 j = 0; j &amp;lt; inDim1; j++) {
				for (Int32 k = 0; k &amp;lt; inDim2; k++) {
					Int32 size = 1;
					// 1 for the closing '\0' character
					if (j &amp;lt; origDim1 &amp;amp;&amp;amp; k &amp;lt; origDim2) {
						size += GS::ucslen32 (&amp;amp;(*origArrHdl)[lastPos]);
						lastPos += size;
					}
					if (j == inIndex1 &amp;amp;&amp;amp; k == inIndex2 &amp;amp;&amp;amp; inParVal != NULL)
						newSize += GS::ucslen32 (inParVal) + 1;
					else
						newSize += size;
				}
			}

			GS::uchar_t **newArrHdl = (GS::uchar_t **) BMAllocateHandle (newSize * sizeof (GS::uchar_t), ALLOCATE_CLEAR, 0);

			// changing array size if needed:
			if (origDim1 != inDim1 || origDim2 != inDim2) {
				(*inMemo-&amp;gt;params)&lt;I&gt;.dim1 = inDim1;
				(*inMemo-&amp;gt;params)&lt;I&gt;.dim2 = inDim2;
			}

			// changing array content:
			Int32 lastPosO = 0;
			Int32 lastPosN = 0;
			for (Int32 j = 0; j &amp;lt; inDim1; j++) {
				for (Int32 k = 0; k &amp;lt; inDim2; k++) {
					if (j == inIndex1 &amp;amp;&amp;amp; k == inIndex2 &amp;amp;&amp;amp; inParVal != NULL) {
						GS::ucscpy (&amp;amp;(*newArrHdl)[lastPosN], inParVal);
						lastPosN += GS::ucslen32 (&amp;amp;(*newArrHdl)[lastPosN]) + 1;
						continue;
					}
					if (j &amp;lt; origDim1 &amp;amp;&amp;amp; k &amp;lt; origDim2) {
						GS::ucscpy (&amp;amp;(*newArrHdl)[lastPosN], &amp;amp;(*origArrHdl)[lastPosO]);
						lastPosO += GS::ucslen32 (&amp;amp;(*origArrHdl)[lastPosO]) + 1;
						lastPosN += GS::ucslen32 (&amp;amp;(*newArrHdl)[lastPosN]) + 1;
					} else {
						GS::ucscpy (&amp;amp;(*newArrHdl)[lastPosN], L("\0"));
						// '\0' character for the empty items
						lastPosN += GS::ucslen32 (&amp;amp;(*newArrHdl)[lastPosN]) + 1;
					}
				}
			}

			// kill original array handle and change it to the new
			BMKillHandle ((GSHandle *) &amp;amp;origArrHdl);
			(*inMemo-&amp;gt;params)&lt;I&gt;.value.array = (GSHandle) newArrHdl;

			return true;
		}
	}

	return false;

}		// ChangeArrayParam
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

Regards, Akos</description>
    <pubDate>Thu, 17 Jul 2014 08:23:45 GMT</pubDate>
    <dc:creator>Akos Somorjai</dc:creator>
    <dc:date>2014-07-17T08:23:45Z</dc:date>
    <item>
      <title>How set to a text array&amp;#65311;&amp;#65311;</title>
      <link>https://community.graphisoft.com/t5/GDL/How-set-to-a-text-array-amp-65311-amp-65311/m-p/173888#M5327</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;&lt;R&gt;I create a text-type array in GDL-object， I use it in source，but I found that I can‘t add text-type’s value to the text-type array。&lt;BR /&gt;
&lt;BR /&gt;
EX Source：
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;char cTmp[256];
GSHandle handle = params.value.array;

BMKillHandle((GSHandle *) &amp;amp;handle);
handle = BMAllocateHandle(sizeof(GS::uchar_t) * 256, ALLOCATE_CLEAR, NULL );

GS::uchar_t*  pRealValue = (GS::uchar_t *)*handle;

sprintf(cTmp,"HANDRAIL_%d",1);
GS::UniString tmp1("1");
GS::ucscpy(pRealValue, tmp1.ToUStr());
&lt;/PRE&gt;

Who can help me？&lt;BR /&gt;
Whatever the result,thank you for you advice！&lt;/R&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 23 May 2023 14:38:23 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/How-set-to-a-text-array-amp-65311-amp-65311/m-p/173888#M5327</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-23T14:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: How set to a text array&amp;#65311;&amp;#65311;</title>
      <link>https://community.graphisoft.com/t5/GDL/How-set-to-a-text-array-amp-65311-amp-65311/m-p/173889#M5328</link>
      <description>&lt;BLOCKQUOTE&gt;QBai wrote:&lt;BR /&gt;I create a text-type array in GDL-object， I use it in source，but I found that I can‘t add text-type’s value to the text-type array。&lt;BR /&gt;
&lt;BR /&gt;
EX Source：
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;char cTmp[256];
GSHandle handle = params.value.array;

BMKillHandle((GSHandle *) &amp;amp;handle);
handle = BMAllocateHandle(sizeof(GS::uchar_t) * 256, ALLOCATE_CLEAR, NULL );

GS::uchar_t*  pRealValue = (GS::uchar_t *)*handle;

sprintf(cTmp,"HANDRAIL_%d",1);
GS::UniString tmp1("1");
GS::ucscpy(pRealValue, tmp1.ToUStr());
&lt;/PRE&gt;

Who can help me？&lt;BR /&gt;
Whatever the result,thank you for you advice！&lt;/BLOCKQUOTE&gt;

Hi,&lt;BR /&gt;
&lt;BR /&gt;
Here's a sample code from the AC18 Element_Modify.cpp file; it may point you to the right direction:&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;bool ChangeArrayParam (API_ElementMemo		*inMemo, 		// memo of the given library part element
                       const char			*paramName,
					   Int32 				inDim1,			// the new first dimension
					   Int32 				inDim2,			// the new second dimension
					   const GS::uchar_t	*inParVal,		// the new value
					   Int32 				inIndex1,		// first index of the new value
					   Int32 				inIndex2)		// second index of the new value
{
	Int32 n = BMGetHandleSize ((GSHandle) inMemo-&amp;gt;params) / sizeof (API_AddParType);

	if (inIndex1 &amp;gt;= inDim1 || inIndex2 &amp;gt;= inDim2 || inIndex1 &amp;lt; 0 || inIndex2 &amp;lt; 0 || inParVal == NULL)
		return false;
	// Bad parameters

	// searching for an array parameter
	for (Int32 i = 0; i &amp;lt; n; i++) {
		// check if it's an array parameter and the array contains strings
		if ((*inMemo-&amp;gt;params)&lt;I&gt;.typeMod == API_ParArray &amp;amp;&amp;amp;
				((*inMemo-&amp;gt;params)&lt;I&gt;.typeID == APIParT_CString || (*inMemo-&amp;gt;params)&lt;I&gt;.typeID == APIParT_Title) &amp;amp;&amp;amp;
				CHCompareASCII ((*inMemo-&amp;gt;params)&lt;I&gt;.name, paramName) == 0)
		{
			GS::uchar_t **origArrHdl = (GS::uchar_t **) (*inMemo-&amp;gt;params)&lt;I&gt;.value.array;
			Int32 origDim1 = (*inMemo-&amp;gt;params)&lt;I&gt;.dim1;
			Int32 origDim2 = (*inMemo-&amp;gt;params)&lt;I&gt;.dim2;

			// calculating new size of the array
			Int32 newSize = 0;
			Int32 lastPos = 0;
			for (Int32 j = 0; j &amp;lt; inDim1; j++) {
				for (Int32 k = 0; k &amp;lt; inDim2; k++) {
					Int32 size = 1;
					// 1 for the closing '\0' character
					if (j &amp;lt; origDim1 &amp;amp;&amp;amp; k &amp;lt; origDim2) {
						size += GS::ucslen32 (&amp;amp;(*origArrHdl)[lastPos]);
						lastPos += size;
					}
					if (j == inIndex1 &amp;amp;&amp;amp; k == inIndex2 &amp;amp;&amp;amp; inParVal != NULL)
						newSize += GS::ucslen32 (inParVal) + 1;
					else
						newSize += size;
				}
			}

			GS::uchar_t **newArrHdl = (GS::uchar_t **) BMAllocateHandle (newSize * sizeof (GS::uchar_t), ALLOCATE_CLEAR, 0);

			// changing array size if needed:
			if (origDim1 != inDim1 || origDim2 != inDim2) {
				(*inMemo-&amp;gt;params)&lt;I&gt;.dim1 = inDim1;
				(*inMemo-&amp;gt;params)&lt;I&gt;.dim2 = inDim2;
			}

			// changing array content:
			Int32 lastPosO = 0;
			Int32 lastPosN = 0;
			for (Int32 j = 0; j &amp;lt; inDim1; j++) {
				for (Int32 k = 0; k &amp;lt; inDim2; k++) {
					if (j == inIndex1 &amp;amp;&amp;amp; k == inIndex2 &amp;amp;&amp;amp; inParVal != NULL) {
						GS::ucscpy (&amp;amp;(*newArrHdl)[lastPosN], inParVal);
						lastPosN += GS::ucslen32 (&amp;amp;(*newArrHdl)[lastPosN]) + 1;
						continue;
					}
					if (j &amp;lt; origDim1 &amp;amp;&amp;amp; k &amp;lt; origDim2) {
						GS::ucscpy (&amp;amp;(*newArrHdl)[lastPosN], &amp;amp;(*origArrHdl)[lastPosO]);
						lastPosO += GS::ucslen32 (&amp;amp;(*origArrHdl)[lastPosO]) + 1;
						lastPosN += GS::ucslen32 (&amp;amp;(*newArrHdl)[lastPosN]) + 1;
					} else {
						GS::ucscpy (&amp;amp;(*newArrHdl)[lastPosN], L("\0"));
						// '\0' character for the empty items
						lastPosN += GS::ucslen32 (&amp;amp;(*newArrHdl)[lastPosN]) + 1;
					}
				}
			}

			// kill original array handle and change it to the new
			BMKillHandle ((GSHandle *) &amp;amp;origArrHdl);
			(*inMemo-&amp;gt;params)&lt;I&gt;.value.array = (GSHandle) newArrHdl;

			return true;
		}
	}

	return false;

}		// ChangeArrayParam
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

Regards, Akos</description>
      <pubDate>Thu, 17 Jul 2014 08:23:45 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/How-set-to-a-text-array-amp-65311-amp-65311/m-p/173889#M5328</guid>
      <dc:creator>Akos Somorjai</dc:creator>
      <dc:date>2014-07-17T08:23:45Z</dc:date>
    </item>
  </channel>
</rss>

