Recent

Author Topic: Appending text to a TMemo  (Read 29864 times)

Bart

  • Hero Member
  • *****
  • Posts: 3547
    • Bart en Mariska's Webstek
Re: RE: Re: RE: Appending text to a TMemo
« Reply #15 on: November 14, 2007, 11:38:36 am »
Quote from: "Leledumbo"
Quote
Does anyone know how to remove in code the last LineEnding from the memo?

Use Trim;
Code: [Select]
function Trim(const S: widestring): widestring;

I'm sorry I did not make myself clear.
What I meant was: how do I remove in code the LineEning from the memo that was added by setting the TMemo text property in code (Memo.Text := SomeText). So that it is removed from the memo itself.
If we can do this, then we can modify SetTextStr() to prevent TMemo from adding a LineEnding if we set the textproperty of a TMemo control, thus fixing the bug.

Bart

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
RE: Re: RE: Re: RE: Appending text to a TMemo
« Reply #16 on: November 15, 2007, 11:29:08 am »
The last lineend is the result of the used TStrings.text. It contains lines, when the Text is "askes" all lines are concatinated whith a terminating LineEnding
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Bart

  • Hero Member
  • *****
  • Posts: 3547
    • Bart en Mariska's Webstek
Re: RE: Re: RE: Re: RE: Appending text to a TMemo
« Reply #17 on: November 15, 2007, 03:52:55 pm »
Quote from: "Marc"
The last lineend is the result of the used TStrings.text. It contains lines, when the Text is "askes" all lines are concatinated whith a terminating LineEnding
Yes, but that is undesired when setting text in a TMemo (and not compatible with Delphi behaviour).

The most logical place to resolve this IMHO is the SetTextStr procedure. This would involve removing the last LineEnding after setting the text.
If that can be done, the bug is fixed.

Bart

tech-pro

  • Full Member
  • ***
  • Posts: 173
    • Tech-Pro.net
RE: Re: RE: Re: RE: Re: RE: Appending text to a TMemo
« Reply #18 on: November 15, 2007, 07:37:07 pm »
You need to be sure that you don't remove the line ending if the string set by the user ended in one. This has been one of the difficulties in producing a workaround.

By the way I still haven't managed to stop the flicker when the memo gets updated. Tried double buffering it, and used BeginUpdateBounds/EndUpdateBounds (admittedly without being able to figure out what they do) to no avail.
Julian

Bart

  • Hero Member
  • *****
  • Posts: 3547
    • Bart en Mariska's Webstek
Re: RE: Re: RE: Re: RE: Re: RE: Appending text to a TMemo
« Reply #19 on: November 15, 2007, 11:18:37 pm »
Quote from: "tech-pro"
You need to be sure that you don't remove the line ending if the string set by the user ended in one. This has been one of the difficulties in producing a workaround.

That should not be so hard? If user sets text, we know what text will be, so we know if it ends in LineEnding. If it does not, then we remove last LineEnding after we set text.

It can be done. Delphi does it, so why can't we?

Bart

tech-pro

  • Full Member
  • ***
  • Posts: 173
    • Tech-Pro.net
RE: Re: RE: Re: RE: Re: RE: Re: RE: Appending text to a TMem
« Reply #20 on: November 16, 2007, 12:44:00 pm »
I wasn't suggesting it can't be done, I just wanted to make the point that sometimes a line ending will be the last thing in the text.

A fix for this won't solve the problem of the memo flickering when it is updated. It seems to me that this is happening because it has to be updated in two stages. First the new text is set, and the control displays it starting with the first line. Then I have to set the caret position to the end, so that the last character entered is in view. If the length of the text is greater than can fit in the visible area, it scrolls, and this causes the flickering.

LCL components don't seem to have the BeginUpdate / EndUpdate methods suggested earlier in this thread. There is BeginUpdateBounds and EndUpdateBounds but I don't know what they do, and when I tried them anyway they didn't deem to do anything.
Julian