I'm trying to convert a tmemo procedure of mine into a trichedit,
routine (by changing tmemo to trichedit & memo to richedit2). The
procedure "snipmemotext" is supposed to do 2 things: (a) limit the
richedit (previously a tmemo) to max_memo_lines (this works); and (b)
scroll to the bottom of the trichedit (previously a tmemo) - this
doesn't seem to work as I just get a white richedit, like it's scrolled
too far down. What am I doing wrong??? and more to the point, how do I
fix it???
Regards,
Peter Williams :)))
const
max_memo_lines = 10; // *****
procedure TPlayer_Main_form.SnipMemoText(var Richedit2 : TRichedit;
MaxSize : integer);
var
SelStartFromEnd, i : integer;
begin
SelStartFromEnd := Length(Richedit2.Text) - Richedit2.SelStart; //
get cursor position
// make it faster with BeginUpdate / EndUpdate {delete excess lines}
Richedit2.Lines.BeginUpdate;
for i := 0 to Richedit2.Lines.Count - MaxSize - 1 do
Richedit2.Lines.Delete(0);
Richedit2.Lines.EndUpDate;
// set cursor position {get cursor on top line}
Richedit2.SelStart := Length(Richedit2.Text) - SelStartFromEnd;
with Richedit2 do
Perform(EM_LINESCROLL, 0, Perform(EM_LINEFROMCHAR,
Richedit2.SelStart, 0) -
Perform(EM_GETFIRSTVISIBLELINE, 0, 0));
end;
Sent via Deja.com http://www.deja.com/
Before you buy.
Actually you can't see the effect I was talking about in that
example because max_memo_lines in too small. Change it to:
max_memo_lines = 100;
Then you will see the effect I'm talking about, e.g. the richedit
DOES scroll down, but it scrolls too far down and all you see is a
white richedit. (PS - I made max_memo_lines 10 to check that it was
deleting lines correctly, which it is).
I hope someone has an answer for me.
Regards,
Peter Williams :)))
In article <8sof4a$8vm$1...@nnrp1.deja.com>,
I got it. Isn't it nice when things work out simply? Here's what I
ended up using:
procedure Tform1.SnipMemoText(var Richedit2 : TRichedit; MaxSize :
integer);
var
i : integer;
begin
// make it faster with BeginUpdate / EndUpdate {delete excess lines}
Richedit2.Lines.BeginUpdate;
for i := 0 to Richedit2.Lines.Count - MaxSize - 1 do
Richedit2.Lines.Delete(0);
Richedit2.Lines.EndUpDate;
// go to the last line of the Richedit
Richedit2.SelStart := Length(Richedit2.Text);
end;
{---------------------------------------------------------}
(it deletes the first (lines.count - max_memo_lines) lines of richedit2
then displays the last line (actually there is a blank line displayed
after the last line, but I can live with that).
Regards,
Peter Williams :)))
In article <8sq757$mht$1...@nnrp1.deja.com>,
Peter Williams <pete...@my-deja.com> wrote:
> Hi All,
>
> Actually you can't see the effect I was talking about in that
> example because max_memo_lines in too small. Change it to:
>
> max_memo_lines = 100;
>
> Then you will see the effect I'm talking about, e.g. the richedit
> DOES scroll down, but it scrolls too far down and all you see is a
> white richedit. (PS - I made max_memo_lines 10 to check that it was
> deleting lines correctly, which it is).
>
> I hope someone has an answer for me.
>
> Regards,
> Peter Williams :)))
>
> In article <8sof4a$8vm$1...@nnrp1.deja.com>,
> Peter Williams <pete...@my-deja.com> wrote:
>Perform(EM_LINEFROMCHAR, Richedit2.SelStart, 0) -
Shouldn't you be using EM_EXLINEFROMCHAR, that's recommended for richedits.
Perform(EM_EXLINEFROMCHAR, 0, Richedit2.SelStart)
Note reversal of parameter values.
I have on rare occasion experience had "with . . ." being applied only to the
first non-fully-qualified names (don't know why), but try fully qualifying the
names - in case.
Is the text you are placing in the richedit RTF or plain text.
Alan Lloyd
alan...@aol.com
It's just plain text. I'm not at all familiar with EM_LINEFROMCHAR
and EM_EXLINEFROMCHAR ... I actually got the code from this ng, for a
memo, and tried to make it work for a richedit. BTW - my other post
where I thought I had found a simply solution, only half works e.g. it
worked for my test program adding 200 lines (limiting to 100), but
didn't scroll to the bottom in the real program (using selstart :=
length(richedit2.text) which DID work in the test program).
I'll test what you posted later, as I'm going out soon. Thanks.
Regards,
Peter Williams :)))
In article <20001020172412...@nso-fa.aol.com>,
alang...@aol.com (AlanGLLoyd) wrote:
> In article <8sof4a$8vm$1...@nnrp1.deja.com>, Peter Williams <petewill@my-
deja.com>
> writes:
>
> >Perform(EM_LINEFROMCHAR, Richedit2.SelStart, 0) -
>
> Shouldn't you be using EM_EXLINEFROMCHAR, that's recommended for
richedits.
>
> Perform(EM_EXLINEFROMCHAR, 0, Richedit2.SelStart)
>
> Note reversal of parameter values.
>
> I have on rare occasion experience had "with . . ." being applied
only to the
> first non-fully-qualified names (don't know why), but try fully
qualifying the
> names - in case.
>
> Is the text you are placing in the richedit RTF or plain text.
>
> Alan Lloyd
> alan...@aol.com
>
>
Delphi 5.0 Std gives an undeclared identifier error on
EM_EXLINEFROMCHAR, and I can't find it anywhere in the help. Were you
thinking of something else ???
Regards,
Peter Williams :)))
-- From the help file. ---
Edit Control Messages
Following are the messages used with edit controls.
EM_CANUNDO
EM_CHARFROMPOS
EM_EMPTYUNDOBUFFER
EM_FMTLINES
EM_GETFIRSTVISIBLELINE
EM_GETHANDLE
EM_GETLIMITTEXT
EM_GETLINE
EM_GETLINECOUNT
EM_GETMARGINS
EM_GETMODIFY
EM_GETPASSWORDCHAR
EM_GETRECT
EM_GETSEL
EM_GETTHUMB
EM_GETWORDBREAKPROC
EM_LIMITTEXT
EM_LINEFROMCHAR
EM_LINEINDEX
EM_LINELENGTH
EM_LINESCROLL
EM_POSFROMCHAR
EM_REPLACESEL
EM_SCROLL
EM_SCROLLCARET
EM_SETHANDLE
EM_SETLIMITTEXT
EM_SETMARGINS
EM_SETMODIFY
EM_SETPASSWORDCHAR
EM_SETREADONLY
EM_SETRECT
EM_SETRECTNP
EM_SETSEL
EM_SETTABSTOPS
EM_SETWORDBREAK
EM_SETWORDBREAKPROC
EM_UNDO
EN_CHANGE
EN_ERRSPACE
EN_HSCROLL
EN_KILLFOCUS
EN_MAXTEXT
EN_SETFOCUS
EN_UPDATE
EN_VSCROLL
WM_COMMAND
WM_COPY
WM_CTLCOLOREDIT
WM_CUT
WM_PASTE
WM_UNDO
procedure TPlayer_Main_form.SnipMemoText(var Richedit2 : TRichedit;
MaxSize : integer);
var
SelStartFromEnd, i : integer;
begin
SelStartFromEnd := Length(Richedit2.Text) - Richedit2.SelStart; //
get cursor position
// make it faster with BeginUpdate / EndUpdate {delete excess
lines} Richedit2.Lines.BeginUpdate;
for i := 0 to Richedit2.Lines.Count - MaxSize - 1 do
Richedit2.Lines.Delete(0);
Richedit2.Lines.EndUpDate;
// set cursor position {get cursor on top line}
Richedit2.SelStart := Length(Richedit2.Text) - SelStartFromEnd;
with Richedit2 do
// this next line gives an undeclared identifier error
Perform(EM_LINESCROLL, 0, Perform(EM_EXLINEFROMCHAR, 0,
Richedit2.SelStart) -
Perform(EM_GETFIRSTVISIBLELINE, 0, 0));
end; { SnipMemoText }
{---------------------------------------------------------}
In article <20001020172412...@nso-fa.aol.com>,
alang...@aol.com (AlanGLLoyd) wrote:
> In article <8sof4a$8vm$1...@nnrp1.deja.com>, Peter Williams <petewill@my-
deja.com>
> writes:
>
> >Perform(EM_LINEFROMCHAR, Richedit2.SelStart, 0) -
>
> Shouldn't you be using EM_EXLINEFROMCHAR, that's recommended for
richedits.
>
> Perform(EM_EXLINEFROMCHAR, 0, Richedit2.SelStart)
>
> Note reversal of parameter values.
>
> I have on rare occasion experience had "with . . ." being applied
only to the
> first non-fully-qualified names (don't know why), but try fully
qualifying the
> names - in case.
>
> Is the text you are placing in the richedit RTF or plain text.
>
> Alan Lloyd
> alan...@aol.com
>
>
> Delphi 5.0 Std gives an undeclared identifier error on
>EM_EXLINEFROMCHAR, and I can't find it anywhere in the help. Were you
>thinking of something else ???
>
You should have RichEdit in your uses clause. RichEdit.pas (D3) defines the
EM_EXLINEFROMCHAR message constant as :-
EM_EXLINEFROMCHAR = WM_USER + 54;
. . . so it should work OK.
Alan Lloyd
alang...@aol.com