After adding a line, use this call:
    SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0);
This will make the added line visible, scrolling as required.

-- 
francois.pie...@overbyte.be
Embarcadero MVP
http://www.overbyte.be




-----Message d'origine-----
De : delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] De la part
de John Dammeyer
Envoyé : vendredi 14 décembre 2012 11:03
À : 'Moderated List for the Discussion of Delphi Programming
excludingDatabase-related topics'
Objet : RE: What is the best way to add objects to TMemo.Lines

Hi Everyone,

That does add an interesting question.

How to create a screen similar to hyperterm or any serial terminal where the
text is added to the end and the earliest line of the screen is lost.

    Memo.Lines.Add(buf);
    if Memo.Lines.Count > 22 then
        Memo.lines.Delete(0);

As long as the screen is longer than 22 lines the added line is always
visible.  But if the buffer size was to be say 128 so that last 128 lines
are accessible then the new line is added to the end but the Delete(0) in
addition to removing the oldest line also repositions the list starting at
the first.

Having to move a scroll down bar after each entry is tedious.  Especially if
they are lines from a serial port.

Another option is to just remove half the Tmemo buffer.

    if COMTraffic.Lines.Count > 200 then begin
        bufsize := COMTraffic.GetTextlen;
        bufsize := bufsize div 2;
        COMTraffic.Selstart := 0;
        COMTraffic.SelLength := bufsize;
        COMTraffic.SelText;
        COMTraffic.ClearSelection;
    end;


Other suggestions?

John

"ELS! The Solution"
Automation Artisans Inc.
http://www.autoartisans.com/ELS/
Ph. 1 250 544 4950


> -----Original Message-----
> From: delphi-boun...@elists.org
> [mailto:delphi-boun...@elists.org] On Behalf Of Arjang Assadi
> Sent: Thursday, December 13, 2012 12:30 PM
> To: Moderated List for the Discussion of Delphi Programming 
> excludingDatabase-related topics
> Subject: Re: What is the best way to add objects to TMemo.Lines
>
>
> If that is the case why not use TListView instead? TMemo is meant for 
> editing text.
>
>
> On 13 December 2012 20:04, John Barrat <j.bar...@netcom.co.uk> wrote:
>
> > No the only things allowed are to re-order (drag and drop)
> and delete - I
> > cannot see why that should affect the objects or am I
> missing something?
> >
> > JohnB
> >
> > -----Original Message-----
> > From: delphi-boun...@elists.org
> [mailto:delphi-boun...@elists.org] On
> > Behalf
> > Of Stephen Posey
> > Sent: 12 December 2012 15:12
> > To: Moderated List for the Discussion of Delphi Programming
> excluding
> > Database-related topics
> > Subject: Re: What is the best way to add objects to TMemo.Lines
> >
> > Are you going to allow the text in the Memo to be edited?
> >
> > If so, what are the implications for the associated objects
> if the number
> > of
> > lines changes (e.g. someone inserts a line break, types in
> one or more
> > lines, or deletes one or more lines)?
> >
> > Stephen Posey
> > stephenlpo...@earthlink.net
> >
> > -----Original Message-----
> > >From: John Barrat <j.bar...@netcom.co.uk>
> > >Sent: Dec 11, 2012 11:38 AM
> > >To: 'Moderated List for the Discussion of Delphi Programming
> > >       excluding       Database-related topics' <delphi@elists.org>
> > >Subject: What is the best way to add objects to TMemo.Lines
> > >
> > >I seems TMemo.lines only supports the String part of a
> TStrings not the
> > >Objects.
> > >
> > >TMemo.Lines.AddObject compiles fine in fact only the
> string component
> > >is actually loaded.
> > >
> > >
> > >
> > >I need to store an object with this TMemo - how do you
> recommend I do
> > this?
> > >
> > >
> > >
> > >JohnB
> > >
> > >_______________________________________________
> > >Delphi mailing list
> > >Delphi@elists.org
> > >http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
> >
> > _______________________________________________
> > Delphi mailing list
> > Delphi@elists.org
> > http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
> >
> > _______________________________________________
> > Delphi mailing list
> > Delphi@elists.org
> > http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
> >
> _______________________________________________
> Delphi mailing list
> Delphi@elists.org
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
>

_______________________________________________
Delphi mailing list
Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list
Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to