Wednesday, 15 February 2012

Why am I getting an incorrect array size from lazarus? -



Why am I getting an incorrect array size from lazarus? -

i have array beingness created parsing semi-colon delimited list.

the splitting of string array works , if utilize for-in , display each element right results.

procedure badsizeofdemo(arraystring: string); var semicolonsplitline: tstringlist; begin semicolonsplitline:= tstringlist.create; semicolonsplitline.strictdelimiter := true; semicolonsplitline.delimiter:= ';'; semicolonsplitline.delimitedtext:= arraystring; showmessage('arraystring: ' + arraystring); showmessage('size of split line: ' + inttostr(sizeof(semicolonsplitline))); end;

with above code size of array '4' when arraystring contains ''.

am missing fundamental here?

further processing next switch using .count

after splitting array for-in , check every element can converted number before building array of integers.

this works, when seek size of integer array illegal qualifier error.

procedure badsizeofdemo(arraystring: string); var semicolonsplitline: tstringlist; myelement: string = ''; myintegerarray: array of integer; count: integer = 0; begin semicolonsplitline:= tstringlist.create; semicolonsplitline.strictdelimiter := true; semicolonsplitline.delimiter:= ';'; semicolonsplitline.delimitedtext:= arraystring; showmessage('arraystring: ' + arraystring); showmessage('size of split line: ' + inttostr(semicolonsplitline.count)); myelement in semicolonsplitline begin seek showmessage('field split line: ' + myelement); myintegerarray[count]:=strtoint(myelement); except on e : econverterror showmessage('invalid number encountered'); end; count:=count+1; end; showmessage('myintegerarray has ' + myintegerarray.count + ' elements'); end;

arrays lazarus fpc tstringlist

No comments:

Post a Comment