Jump to content
357mag

My sLineBreak is not working

Recommended Posts

I have a program and there is a Edit box and a few buttons. When the program is run, I want to be able to press a button called Show Values and then you will see two lines of code: The value of x is: 6, and The value of y is 7. But I want each line to print on a new line.

So I put an sLineBreak in there but it's not working. The second line is just printing after the first line. It should look like this:

 

The value of x is 6

The value of y is 7

 

Here is my code so far:

procedure TFormIncrementAndDecrement.ButtonShowValuesClick(Sender: TObject);
  var
    x, y: integer;
begin
  x := 6;
  y := 7;

  EditResult.Text := 'The value of x is: ' + IntToStr(x) + sLineBreak;
  EditResult.Text :=  EditResult.Text + 'The value of y is: ' + IntToStr(y);

 

Share this post


Link to post

A TEdit can only show one line. For multi-lines use a TMemo instead.

  • Like 1

Share this post


Link to post

Thank You, that is working much better. But when I run my program the words MemoResult show in the Memo control. How do I get rid of them? I've looked in the Object Inspector and I don't see a way to remove them from the Memo contol.

Share this post


Link to post
21 minutes ago, 357mag said:

Object Inspector and I don't see a way to remove them from the Memo contol.

It is in lines property,

Share this post


Link to post

In your example, it would be better to use the Lines.Add() method rather than the Text property, then you don't have to worry about using sLineBreak at all, or wasting time and resources to read the Text, append to it, and assign it back.

procedure TFormIncrementAndDecrement.ButtonShowValuesClick(Sender: TObject);
var
  x, y: integer;
begin
  x := 6;
  y := 7;

  MemoResult.Clear;
  MemoResult.Lines.Add('The value of x is: ' + IntToStr(x));
  MemoResult.Lines.Add('The value of y is: ' + IntToStr(y));
end;

 

Edited by Remy Lebeau
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×