BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help me wrestle with TMemo.KeyDown ?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Alan Mead
Guest





PostPosted: Sat Nov 20, 2004 6:36 am    Post subject: Help me wrestle with TMemo.KeyDown ? Reply with quote



Hi, I'm new to this group, Delphi and Windows.

I'd like users to be able to select all the text in a memo component by
pressing contol-a when the memo has focus. Here's my code:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key:Word; Shift:
TShiftState); begin
if (Key=Ord('A')) and (ssCtrl IN Shift) then
Memo1.SelectAll;
end;

As a point of comparison, when I do this in Lazarus, it works perfectly.
When I do this in Delphi 7, the text is not selected but the cursor moves
to the leftmost position of the current line. I notice that control-e
moves to the rightmost position.

I tentatively conclude that the VCL has some functionality hidden to do
this... My hot-keys and the default are in contention.

How does a Delphi programmer investigate and fix this sort of thing?

-Alan
Back to top
Berend Veldkamp
Guest





PostPosted: Fri Nov 26, 2004 12:08 pm    Post subject: Re: Help me wrestle with TMemo.KeyDown ? Reply with quote



Alan Mead wrote:

Quote:
Hi, I'm new to this group, Delphi and Windows.

I'd like users to be able to select all the text in a memo component by
pressing contol-a when the memo has focus. Here's my code:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key:Word; Shift:
TShiftState); begin
if (Key=Ord('A')) and (ssCtrl IN Shift) then
Memo1.SelectAll;
end;

As a point of comparison, when I do this in Lazarus, it works perfectly.
When I do this in Delphi 7, the text is not selected but the cursor moves
to the leftmost position of the current line. I notice that control-e
moves to the rightmost position.

I tentatively conclude that the VCL has some functionality hidden to do
this... My hot-keys and the default are in contention.

How does a Delphi programmer investigate and fix this sort of thing?

-Alan

In D6 your code works fine, you might try to use a TActionlist, though.
Create a new action and assign Ctrl+A to the "Shortcut" property, then
in the OnExecute code put:
if memo1.Focused then
memo1.SelectAll;

Back to top
Alan Mead
Guest





PostPosted: Fri Nov 26, 2004 9:03 pm    Post subject: [SOLVED] Re: Help me wrestle with TMemo.KeyDown ? Reply with quote



On Fri, 26 Nov 2004 13:08:50 +0100, Berend Veldkamp wrote:

Quote:
Alan Mead wrote:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key:Word; Shift:
TShiftState); begin
if (Key=Ord('A')) and (ssCtrl IN Shift) then
Memo1.SelectAll;
end;

In D6 your code works fine, you might try to use a TActionlist, though.
Create a new action and assign Ctrl+A to the "Shortcut" property, then
in the OnExecute code put:
if memo1.Focused then
memo1.SelectAll;

Thanks for this suggestion. I'll have to examine the TActionList
functionality. Upon a suggestion from someone in another forum, I moved my
code to KeyUp and added "Key := 0;" after the SelectAll and one or both of
those changes allowed me to override the default behavior.

-Alan


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.