Multiple Line Addition in TMEMO
delphi
Solution
To add more text to a memo control, call either `Append` or `Add`, like this:
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add('Line1');
Memo1.Lines.Add('Line2');
end;
....
....
....
....
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Lines.Add('Line3');
Memo1.Lines.Add('Line4');
end;
If you need to clear the contents...
Memo1.Lines.Clear;
And if you wish to replace a line (only if the index already exists):
Memo1.Lines[2]:= 'Replacement Text';
To delete one of the lines...
Memo1.Lines.Delete(2);
Problem
I am having one Delphi XE2 Project with 2 Buttons (Button1, Button2) and 1 Memo (Memo1). My requirement is that on Button1 Click Some Text will be witten to Memo1 in the First Line (Line1). If I click again on Button1 Some New Text will be written in a New Line (Line2). If I click on Button2 the Another New Text will be appended in Memo1 (After Last Line a new Line will be created). So I have written the following code : ``` procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.Text :='Line1'; Memo1.Lines.Text :='Line2'; end; .... .... .... .... procedure TForm1.Button2Click(Sender: TObject); begin Memo1.Lines.Text :='Line3'; Memo1.Lines.Text :='Line4'; end; ``` But the problem is that only one line is showing with text as "Line1" on Button1FirstClick, "Line2" on Button1SecondClick and "Line4" on Button2Click. Please help me.