Reputation: 21
How can I make a tMemo display starting at the top item please? I have not found anything like a "TopItem", and wonder if it has to be done by somehow sending messages (keydown control, keydown home, keyup home, keyup control) but despite reading large tracts of the Delphi Help I haven't worked out how to do this either.
Upvotes: 1
Views: 137
Reputation: 25
Isn't it just:
Memo.SelStart := 0;
Memo.SelLength := 0;
Add this code of course after you have filled your Tmemo with its contents ... (This works for me)
Upvotes: 0
Reputation: 21
Steve88, thanks for trying, but that did not work. Got some ideas from a post from Peter Below, which led me to the following, which actually works!
There are some funnies as to whether to use MemoPopup.Perform or PostMessage, and I hope someone can shed light on the workings of these.
// Trying to get a tMemo to display its contents, starting at the first line.
// Various ideas from assorted net sites, and Peter Below's reply to someone
// with a similar problem - thanks, Peter!
// A couple of bits left in for people to puzzle over as to why they do or don't work!!
uses Winapi.Windows, Winapi.Messages;
var
KeyStateBefore, KeyStateUse : tKeyboardState;
begin
PostMessage(MemoPopup.Handle, WM_KeyDown, ord('A'), 0); //'a' gets through
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, ord('K'), 0); //This does not
Application.ProcessMessages;
GetKeyboardState(KeyStateBefore);
KeyStateUse := KeyStateBefore;
KeyStateUse[vk_Control] := $81;
SetKeyBoardState(KeyStateUse); //Now turn on the control key.
//These do appear to work as expected.
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, vk_Home, 0);
MemoPopup.Perform(WinApi.Messages.WM_KEYUP, vk_Home, 0);
Application.ProcessMessages;
SetKeyboardState(KeyStateBefore); //Remove the control key.
PostMessage(MemoPopup.Handle, WM_KeyDown, ord('B'), 0); //Got through, lower case
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, ord('E'), 0); //Nope
Application.ProcessMessages;
KeyStateUse := KeyStateBefore;
KeyStateUse[vk_Shift] := $80;
SetKeyboardState(KeyStateUse);
PostMessage(MemoPopup.Handle, WM_KeyDown, ord('C'), 0); //Got through in upper case
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, ord('Q'), 0); //Not this though
Application.ProcessMessages;
SetKeyBoardState(KeyStateBefore);
Application.ProcessMessages;
end;
Upvotes: 0
Reputation: 2416
Just select any character depending on what you want visible in Lines.
Memo.Lines.SelStart:=0;
Memo.Lines.SelLength:=1;
Upvotes: 0