 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alan Mead Guest
|
Posted: Sat Nov 20, 2004 6:36 am Post subject: Help me wrestle with TMemo.KeyDown ? |
|
|
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
|
Posted: Fri Nov 26, 2004 12:08 pm Post subject: Re: Help me wrestle with TMemo.KeyDown ? |
|
|
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
|
Posted: Fri Nov 26, 2004 9:03 pm Post subject: [SOLVED] Re: Help me wrestle with TMemo.KeyDown ? |
|
|
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 |
|
 |
|
|
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
|
|