Footy
2012-10-19 19:41:56
Okay, so I have a string declared named String1. I have a TStringArray declared named StringArray1. How do I add String1 into StringArray1?
Thanks!
Footy
Thanks!
Footy
2012-10-19 19:41:56
2012-10-19 19:44:58
SetLength(StringArray1, Length(StringArray1) + 1);
StringArray1[ ] := String1;2012-10-19 19:46:11
2012-10-19 20:13:24
2012-10-20 02:17:36
2012-10-20 02:28:28
From: litoris
Wait, can't you add it to the array without extending the length first?
2012-10-20 17:57:09
Procedure Button2Click(Sender: TObject);
Begin
SetLength(UsernameArray, Length(UsernameArray) + 1);
UsernameArray[ ] := frmdesign.edit1.TEXT;
End;
2012-10-20 18:06:25
From: Footy
An addition the the above question:
I'm making a form, and I'm trying to add the text in edit1 to the UsernameArray. However, when I run the below code, I get a syntax error. I'm putting a string(Edit1.Text) into a TStringArray(UsernameArray). Any Idea what the problem is?Procedure Button2Click(Sender: TObject);
Begin
SetLength(UsernameArray, Length(UsernameArray) + 1);
UsernameArray[ ] := frmdesign.edit1.TEXT;
End;
2012-10-20 18:08:53
2012-10-20 18:11:59
2012-10-20 21:42:02
From: Nebula
Semi-my fault for assuming you knew something that you don't
say you have an array of integers such as:
[4, 3, 2, 6, 5, 8]
and lets say you want to add a 9 to the end. SetLength(UsernameArray, Length(UsernameArray) + 1) creates a new space for a new value to be added:
[4, 3, 2, 6, 5, 8, ]
That new space is 6th in the array.
To give the 6th place a new value, put a 6 in the brackets.
Array[6] := 9;
of course you won't be using a 6, you would be using the last point in the array, so use Length(UsernameArray)
UsernameArray[Length(UsernameArray)] := frmdesign.edit1.TEXT;
2012-10-20 21:57:55
2012-10-20 22:03:32