Musisback Posted June 1, 2011 Share Posted June 1, 2011 String contain a maximun of 255 chars. I need functions that process much longer strings, so i use dynarray of char as parameters. But I seem like is is impossible to allocate any type of dynarray given as parameter inside a function or procedure. ( the strings functions allocate automaticly the array of char but VS won't return the resized array ouside the procedure) So how is is possible to prosses longstring in a procedure ?? Quote Link to comment
Dieter @ DWorks Posted June 1, 2011 Share Posted June 1, 2011 You can use dynarrays as parameters, but you can't resize them in a subprocedure. So resize them first and then send them to the function or procedure. Quote Link to comment
Musisback Posted June 1, 2011 Author Share Posted June 1, 2011 (edited) Thanks Dworks, So if I want modify a dynarray of char with is procedure, I need to 1 run a funtion that calculate the future size of the dynarray 2 reallocate the dynarray 3 run the function that modifies it. Is that correct? I guess it is possible, but not very practical or efficient... Edited June 1, 2011 by musisback Quote Link to comment
JBenghiat Posted June 1, 2011 Share Posted June 1, 2011 This is from the hip, so you'll have to verify. I believe the way to pass a char dynarray to a subfunction is by passing the dynarray as a VAR parameter. so: PROCEDURE SubProc(VAR subArray: DYNARRAY [] of CHAR); BEGIN {Do stuff to subArray} END; BEGIN mainArray:='foobar x 100'; SubProc(mainArray); END; -Josh Quote Link to comment
Miguel Barrera Posted June 1, 2011 Share Posted June 1, 2011 You do not have to size DYNARRAY[] OF CHAR before passing it to a procedure as a variable parameter; you only have to assign text to the variable before passing it on: PROCEDURE TestString; VAR aString: DYNARRAY[] OF CHAR; PROCEDURE ChgText(VAR varString: DYNARRAY[] OF CHAR); BEGIN varString:= 'The string has been modified'; END; BEGIN aString:= ''; ChgText(aString); Message(aString); END; However, other types of Dynarrays do need to be sized before passing to a procedure or function: VAR strArray: DYNARRAY[] OF STRING; ... PROCEDURE ProcessStrArray(VAR strList: DYNARRAY[] OF STRING); BEGIN ..... END; BEGIN ... totItems:= 20; Allocate strArray[1..totItems]; ProcessStrArray(strArray); ... END; Quote Link to comment
Dieter @ DWorks Posted June 3, 2011 Share Posted June 3, 2011 You do not have to size DYNARRAY[] OF CHAR before passing it to a procedure as a variable parameter; you only have to assign text to the variable before passing it on: PROCEDURE TestString; VAR aString: DYNARRAY[] OF CHAR; PROCEDURE ChgText(VAR varString: DYNARRAY[] OF CHAR); BEGIN varString:= 'The string has been modified'; END; BEGIN aString:= ''; ChgText(aString); Message(aString); END; However, other types of Dynarrays do need to be sized before passing to a procedure or function: VAR strArray: DYNARRAY[] OF STRING; ... PROCEDURE ProcessStrArray(VAR strList: DYNARRAY[] OF STRING); BEGIN ..... END; BEGIN ... totItems:= 20; Allocate strArray[1..totItems]; ProcessStrArray(strArray); ... END; So only dynarrays of string doesn't have to be resized before. I hardly ever use them, so I thought they would fit the logic of the others. VS is full of these unlogical things. Quote Link to comment
Miguel Barrera Posted June 3, 2011 Share Posted June 3, 2011 Let's not get char and string arrays mixed up and that is why I picked these two to show the difference. The DYNARRAY OF CHAR, which is a single variable string of 2M char maximum, does not need to be sized before but it needs to be assigned before passing to a procedure/function as a parameter. The DYNARRAY OF STRING, which is an array of strings with 255 char each, as well as any other VS and user defined types, need to be sized before passing to a procedure/function. Quote Link to comment
Musisback Posted June 7, 2011 Author Share Posted June 7, 2011 I reask my question because it kinda went out of subject. I added a couples line to the TestString procedure to help me explain PROCEDURE TestString; VAR shortstring : STRING; aString : DYNARRAY[] OF CHAR; PROCEDURE ChgText(VAR varString: DYNARRAY[] OF CHAR); BEGIN varString:= 'The string has been modified'; END; BEGIN aString:= 'Only 13 chars'; ChgText(aString); shortstring := aString; Message(shortstring ); END; run(TestString); This procedure display : The string ha so, only the 13 first chars. It thing it is because then dynarray of char, like any other dynarray is allocate before the ChgText procedure : 13 chars when passed to a string, only the 13 first chars are taken into account. Is there a way around this ? Thanks, Quote Link to comment
MullinRJ Posted June 7, 2011 Share Posted June 7, 2011 This appears to be a bug. I tried preallocating the Dynarray to a value larger than one you needed, but your assignment still brings the allocation back to 13. Not good. PROCEDURE TestString; CONST LargeNumber = 32767; { max 32767 } VAR shortstring : STRING; aString : DYNARRAY OF CHAR; PROCEDURE ChgText(VAR varString: DYNARRAY OF CHAR); BEGIN varString := 'The string has been modified'; END; BEGIN Allocate aString [1 .. LargeNumber]; aString := 'Only 13 chars'; ChgText(aString); shortstring := aString; Message(shortstring ); END; run(TestString); Raymond Quote Link to comment
maarten. Posted June 7, 2011 Share Posted June 7, 2011 This is a bug indeed, I noticed somewhat the same behavior some months ago. I tried different things but I was hold back everytime because you can not allocate a VAR parameter and you can not return a dynarray in a function. So I ended up using a Array[1..20000] of CHAR in my variables and in my VAR parameters of my functions an procedures. That worked, not fast (but that wasn't a problem, it was a script to run at night), not sure if it will work fast enough for you too Sleg. I really hope that one day, NNA will get rid of that ridiculous max of 255 chars for strings... This isn't the '80s anymore Quote Link to comment
Musisback Posted June 7, 2011 Author Share Posted June 7, 2011 Thanks for the info. I actually found some work around. (like we need to do too often in Vectorscript and more generally in Vectorworks...) Created 2 functions : The First one calculate the size of the future string, the second assign it its new value. so we got: Allocate theLongString[1..getNewStringSize(theLongString,....)] ModifyLongString(theLongString,....); This is not pretty, this is not efficient, but it works. PS: I now get those "reALLOCATING may cause lost of data" warnings that I cannot get rid off. I guess it is possible with some other extremely unpractical work around.... Quote Link to comment
Miguel Barrera Posted June 7, 2011 Share Posted June 7, 2011 Yes, it is a bug where the length of the returning Dynarray is not reset to the changed string. By reassigning aString with aString:= Concat('',aString); {or probably any other string function} immediately after the function call, the length will be reset. PROCEDURE TestString; VAR shortstring : STRING; aString : DYNARRAY[] OF CHAR; PROCEDURE ChgText(VAR varString: DYNARRAY[] OF CHAR); BEGIN varString:= 'The string has been modified'; END; BEGIN aString:= 'Only 13 chars'; ChgText(aString); aString:= Concat('',aString); shortstring:= aString; Message(shortstring ); END; run(TestString); and Message will display the full string. Quote Link to comment
Musisback Posted June 8, 2011 Author Share Posted June 8, 2011 Thanks Miguel, this way is much easier... Quote Link to comment
Hippocode Posted February 19, 2013 Share Posted February 19, 2013 (edited) I'm looking into placing a long text (>255) into a dialog popup window. I assumed creating the dynarry of char trough this way would work, and it does, but the alrtdialog seems to ignore the string when its too big, I guess on 255 chars. PROCEDURE TestString; VAR aString : DYNARRAY[] OF CHAR; BEGIN aString:=concat('print some text',chr(13)) FOR i:= 1 TO.... aString:=concat(aString,'text',i,chr(13)); END; Message(aString); AlrtDialog(aString); END; run(TestString); can dialogs only accept strings ? Edited February 19, 2013 by hippothamus Quote Link to comment
Vectorworks, Inc Employee klinzey Posted February 19, 2013 Vectorworks, Inc Employee Share Posted February 19, 2013 You can just treat the DynArray the same way you would a string. Some standard dialogs, like message(), can only accept can only accept up to 255 chars. (Also I don't think message will process chr(13) ) If you are displaying the strings in a real dialog you should have no problems. Quote Link to comment
JBenghiat Posted February 19, 2013 Share Posted February 19, 2013 The predefined dialogs are a fixed size, and so only support limited string lengths. If your string is greater than 255 characters (I think alert text may be even smaller), you will have to write a custom dialog. I believe there are some dialog examples on the Vectorworks.net main site under Support>Customization>Vectorscript>Examples. -Josh Quote Link to comment
MullinRJ Posted February 22, 2013 Share Posted February 22, 2013 (Also I don't think message will process chr(13) ) The last few versions of VW will handle chr(13). This is a very nice feature. You may have to resize the Message window manually to see additional lines. Raymond Quote Link to comment
Vectorworks, Inc Employee klinzey Posted February 22, 2013 Vectorworks, Inc Employee Share Posted February 22, 2013 (Also I don't think message will process chr(13) ) The last few versions of VW will handle chr(13). This is a very nice feature. You may have to resize the Message window manually to see additional lines. Raymond Both platforms? I recall chr(13) working on one but not the other. Quote Link to comment
MullinRJ Posted February 22, 2013 Share Posted February 22, 2013 Hi Kevin, ???I'm not sure about the PC. It does work on the Mac. OK, I just tested on the PC - chr(13), chr(10) works on the PC in the Message window. Raymond Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.