要求是做一个个人兴趣爱好的选择,但是很奇怪的是为什么Memo1.lines.string[0] := checkBox1.caption;赋值成功
但是后面的checkBox3-5.caption赋给Memo1.lines.string[2-4]时都是赋空字符串。
procedure TForm1.Button1Click(Sender: TObject);
begin
{ if checkbox1.Checked = true then
memo1.Lines.Strings[0] := (checkbox1.Caption); }
{ if checkbox2.Checked = true then
memo1.Lines.strings[1] := checkbox2.Caption; }
//memo1.Lines.Add(checkbox2.Caption);
if checkbox3.Checked = true then
begin
memo1.Lines.strings[2] := checkbox3.Caption;
ShowMessage(memo1.Lines.strings[2]);
end;
//memo1.Lines.Add(checkbox2.Caption);
if checkbox4.Checked = true then
begin
memo1.Lines.strings[3] := checkbox4.Caption;
ShowMessage(memo1.Lines.strings[3]);
end;
//memo1.Lines.Add(checkbox3.Caption);
if checkbox5.Checked = true then
//memo1.Lines.strings[4] := checkbox5.Caption;
memo1.Lines.Add(checkbox4.Caption);
end;
但是后面的checkBox3-5.caption赋给Memo1.lines.string[2-4]时都是赋空字符串。
procedure TForm1.Button1Click(Sender: TObject);
begin
{ if checkbox1.Checked = true then
memo1.Lines.Strings[0] := (checkbox1.Caption); }
{ if checkbox2.Checked = true then
memo1.Lines.strings[1] := checkbox2.Caption; }
//memo1.Lines.Add(checkbox2.Caption);
if checkbox3.Checked = true then
begin
memo1.Lines.strings[2] := checkbox3.Caption;
ShowMessage(memo1.Lines.strings[2]);
end;
//memo1.Lines.Add(checkbox2.Caption);
if checkbox4.Checked = true then
begin
memo1.Lines.strings[3] := checkbox4.Caption;
ShowMessage(memo1.Lines.strings[3]);
end;
//memo1.Lines.Add(checkbox3.Caption);
if checkbox5.Checked = true then
//memo1.Lines.strings[4] := checkbox5.Caption;
memo1.Lines.Add(checkbox4.Caption);
end;
var
i: integer;
begin
Memo1.Clear;
for i := 0 to 4 do
Memo1.Lines.Add('');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckBox3.Checked = true then
begin
Memo1.Lines.Strings[2] := CheckBox3.Caption;
ShowMessage(Memo1.Lines.Strings[2]);
end;
if CheckBox4.Checked = true then
begin
Memo1.Lines[3] := CheckBox4.Caption;
ShowMessage(Memo1.Lines[3]);
end;
if CheckBox5.Checked = true then
begin
Memo1.Lines.Strings[4] := CheckBox5.Caption;
ShowMessage(Memo1.Lines[4]);
end;
end;上面结果正确。自己分析原因吧!
var
i: integer;
begin
Memo1.Clear;
//for i := 0 to 4 do
// Memo1.Lines.Add('');
end;
谢谢了,只怪自己平时学的不扎实! 就是说Memo1在使用前必须预先分配,否则只有第一行有效
不知道我这么理解对不?