How to store Memo content in variable string in Delphi?

Asked

Viewed 3,002 times

1

I need to store the contents of Memo1 in a string variable, but it didn’t work:

sHTML := Memo1.Lines;

4 answers

4


sHTML := Memo1.Text;

So it will work, now if you need something else, specify in the question.

1

I usually use Memo1.Lines.Text

0

Can be done in the following 3 ways, can create two memos and a botão at the event onClick of the button passes the following code to it:

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
    AText: String;
begin
  Memo2.Lines.Add('Option 1');
  for i := 0 to Memo1.Lines.Count -1 do AText := AText + Memo1.Lines[i];
  Memo2.Text := Memo2.Text + AText;
  Memo2.Lines.Add('--------------------------------------------');

  Memo2.Lines.Add('Option 2');
  AText := Memo1.Lines.Text;
  Memo2.Text := AText;
  Memo2.Lines.Add('--------------------------------------------');

  Memo2.Lines.Add('Option 3');
  AText := Memo1.Text;
  Memo2.Text := Memo2.Text + AText;
  Memo2.Lines.Add('--------------------------------------------');
end;

The second and third option are practically the same, however the first will only pick up the text of each line which can be interesting at certain times, now it will all depend on your needs.

0

If it is variable -> sHTML := Memo1.Text;

If it’s field -> sHTML.AsString := Memo1.Text;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.