2014-06-03 08:41 AM - last edited on 2023-05-23 04:38 PM by Rubia Torres
char cTmp[256]; GSHandle handle = params.value.array; BMKillHandle((GSHandle *) &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());Who can help me?
2014-07-17 10:23 AM
QBai wrote:Hi,
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。
EX Source:char cTmp[256]; GSHandle handle = params.value.array; BMKillHandle((GSHandle *) &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());Who can help me?
Whatever the result,thank you for you advice!
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->params) / sizeof (API_AddParType); if (inIndex1 >= inDim1 || inIndex2 >= inDim2 || inIndex1 < 0 || inIndex2 < 0 || inParVal == NULL) return false; // Bad parameters // searching for an array parameter for (Int32 i = 0; i < n; i++) { // check if it's an array parameter and the array contains strings if ((*inMemo->params).typeMod == API_ParArray && ((*inMemo->params).typeID == APIParT_CString || (*inMemo->params).typeID == APIParT_Title) && CHCompareASCII ((*inMemo->params).name, paramName) == 0) { GS::uchar_t **origArrHdl = (GS::uchar_t **) (*inMemo->params).value.array; Int32 origDim1 = (*inMemo->params).dim1; Int32 origDim2 = (*inMemo->params).dim2; // calculating new size of the array Int32 newSize = 0; Int32 lastPos = 0; for (Int32 j = 0; j < inDim1; j++) { for (Int32 k = 0; k < inDim2; k++) { Int32 size = 1; // 1 for the closing '\0' character if (j < origDim1 && k < origDim2) { size += GS::ucslen32 (&(*origArrHdl)[lastPos]); lastPos += size; } if (j == inIndex1 && k == inIndex2 && 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->params).dim1 = inDim1; (*inMemo->params).dim2 = inDim2; } // changing array content: Int32 lastPosO = 0; Int32 lastPosN = 0; for (Int32 j = 0; j < inDim1; j++) { for (Int32 k = 0; k < inDim2; k++) { if (j == inIndex1 && k == inIndex2 && inParVal != NULL) { GS::ucscpy (&(*newArrHdl)[lastPosN], inParVal); lastPosN += GS::ucslen32 (&(*newArrHdl)[lastPosN]) + 1; continue; } if (j < origDim1 && k < origDim2) { GS::ucscpy (&(*newArrHdl)[lastPosN], &(*origArrHdl)[lastPosO]); lastPosO += GS::ucslen32 (&(*origArrHdl)[lastPosO]) + 1; lastPosN += GS::ucslen32 (&(*newArrHdl)[lastPosN]) + 1; } else { GS::ucscpy (&(*newArrHdl)[lastPosN], L("\0")); // '\0' character for the empty items lastPosN += GS::ucslen32 (&(*newArrHdl)[lastPosN]) + 1; } } } // kill original array handle and change it to the new BMKillHandle ((GSHandle *) &origArrHdl); (*inMemo->params).value.array = (GSHandle) newArrHdl; return true; } } return false; } // ChangeArrayParamRegards, Akos