我想做什么:
在编辑框中输入,在按钮单击时将其写入备忘录框行,当输入0或-1时,转到编辑框的下一行
代码:
procedure TForm1.btnReadClick(Sender: TObject);
var
c, i, j : integer;
ch2 : Char;
txt1, txt2 : string;
begin
c := StrToInt(edt2.Text); //input
ch2 := Converteer(c); //input gets converted to Char
if memC.Lines.Count = 0 then //start value when memo box empty
begin
i := 0;
j := 0;
txt1 :='';
txt2 :='';
end;
if c = 0 then //text naar memo
begin
i := i + 1; // next line ?!? these two seem not to work
txt1 := ''; // empty string ?!? these two seem not to work
txt2 := memT.Lines[j] + ch2;
end
else if c = -1 then //same, it appears 'i' is maybe reset everytime button is pressed
begin
i := i + 1;
j := j + 1;
txt1 := '';
txt2 := '';
end
else if c >= 0 then // a t/m z
begin
txt1 := memC.Lines[i] + IntToStr(c);
txt2 := memT.Lines[j] + ch2;
end;
memC.Lines[i] := txt1; //write string to line , [i] should specify the wich line
memT.Lines[j] := txt2; // same
end.
我无法找到错误的位置/方式,如果有人能帮助我,那就太棒了。
greetz peter
答案 0 :(得分:1)
如果备注框i
不为空,则变量j
,txt1
,txt2
,memC
未初始化。你将它们设置为0 /空如果是 - 在其他情况下你期望它们是什么?请注意,它们的值不会在多次单击按钮时保留,因为您已将它们声明为此函数的本地值...