MEMO
From: Eddie Shipman <eshipman@slip.net>
Found the answer on my own on Delphi WWW Forum.
Var ScrollMessage:TWMVScroll; ScrollMessage.Msg:=WM_VScroll; for i := Memo1.Lines.Count DownTo 0 do begin ScrollMessage.ScrollCode:=sb_LineUp; ScrollMessage.Pos:=0; Memo1.Dispatch(ScrollMessage); end;
From: "David M. Goncalves" <dmgoncal@vicon.net>
> > What I am trying to do is have the current line number updated when > the user navigates through the memo with the cursor keys. >
You are in luck. I have done that very thing. I cut out the functions and put them in a standalone unit. In order for you to test this, simply create a blank form with a single Tmemo on it.
You will want to trap a variety of events. In the code I have provided, I provide a separate event handler for every event, so you can see which ones you want to trap. Some of them you can share with one another.
This sample will display the coordinates (Column, Row) in the form caption.
I do not display coordinates when text is selected, because I wasn't sure how to handle it without being misleading...
Let me know if you have any trouble with this, but it should work fine.
unit Unit1; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; procedure Memo1Change(Sender: TObject); procedure Memo1Click(Sender: TObject); procedure Memo1Enter(Sender: TObject); procedure Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure Memo1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Memo1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } Function GetLineIndex : Word; Function GetStrInsertIndex : Word; procedure GetCursorCoord; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} Function TForm1.GetLineIndex : Word; begin Result:=SendMessage(Memo1.handle,EM_LINEFROMCHAR,memo1.selstart,0); end; Function TForm1.GetStrInsertIndex : word; begin GetStrInsertIndex := memo1.Selstart-SendMessage(Memo1.handle,EM_LINEINDEX,GetLineIndex,0) end; procedure TForm1.GetCursorCoord; var LineIndex: word; LineChar : byte; SelSt : word; begin SelSt:=Memo1.selstart; LineIndex:=GetLineIndex; Linechar:=GetStrInsertIndex; if Memo1.seltext>'' then Caption:='Text Selected' else Caption:='Col '+ inttostr(LineChar+1)+' , ' + 'Row '+ inttostr(Lineindex+1); end; procedure TForm1.Memo1Change(Sender: TObject); begin GetCursorCoord; end; procedure TForm1.Memo1Click(Sender: TObject); begin GetCursorCoord; end; procedure TForm1.Memo1Enter(Sender: TObject); begin GetCursorCoord; end; procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin GetCursorCoord; end; procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin GetCursorCoord; end; procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin GetCursorCoord; end; procedure TForm1.Memo1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin GetCursorCoord; end; end.