add string to memo box line, then empty string, add new input on next line - delphi 2010 - help!
what im trying to do:
input in an edit box, write it to a memo box line on button click, when a 0 or -1 is entered move on to next line of edit box
code:
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.
i cant find where/how it goes wrong, it be awesome if someone 开发者_高级运维could give me a hand.
greetz peter
The variables i
, j
, txt1
, txt2
are uninitialised if the memo box memC
is not empty. You set them to 0/empty if it is - what are you expecting them to be in other cases? Note that their values won't be preserved across multiple button clicks, because you've declared them as local to this function...
精彩评论