I have an array that is being created by parsing a semi-colon delimited list.
The splitting of the string into an array works and if I use a for-in and display each element I get the correct 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 the above code I always get the size of the array as '4' even when the arrayString contains ''
.
Am I missing something fundamental here?
FURTHER PROCESSING following switch to using .Count
After splitting the array like this I then do a for-in
and check that every element can be converted to a number before building an array of integers.
This essentially works, but then when I try to get the size of the integer array I get an 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));
for myElement in semiColonSplitLine do
begin
Try
showMessage('field from split line: ' + myElement);
myIntegerArray[count]:=StrToInt(myElement);
except
On E : EConvertError do
ShowMessage('Invalid number encountered');
end;
count:=count+1;
end;
showMessage('myIntegerArray now has ' + myIntegerArray.Count + ' elements');
end;