Windows Message

I have a edit box and a panel on a form.
When the panel is focused, I press Return key, I  wish the color of the edit box is changed.

I write a procedure like:

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Panel1: TPanel;
  private
    { Private declarations }
  public
     procedure aaa(var msg :Tmessage); Message WM_KeyDown;
    { Public declarations }
  end;

procedure TForm1.aaa(var msg : Tmessage);
begin
  if panel1.Focused then
    if msg.WParam = VK_Return then
       Edit1.Color := clAqua;
end;

It doesn't work. What is the problem? How can fix it?

Thanks.
petershaw9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yingkitCommented:
Listening...
0
hubdogCommented:
I do not know why you code not work
but the code below will work

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
     //procedure aaa(var msg :Tmessage); Message WM_KeyDown;
     procedure aaa(var Msg: TMsg; var Handled: Boolean);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  application.OnMessage:=aaa;
end;

procedure TForm1.aaa(var Msg: TMsg; var Handled: Boolean);
begin
  if Msg.message=wm_keydown then
  begin
    if Panel1.Focused then
    begin
      if msg.WParam = VK_Return then
        Edit1.Color := clAqua;
      handled:=true;
    end;
  end;
end;
0
nricoCommented:
Why don't you simply use the OnKeyPress event of the TEdit?
That would be muuuuuuuuuch easier!
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

philipleighsCommented:
Yes exactly! Easier and a good deal more efficient than an application message handler.

Inside the OnKeyPress event type:

if Key = #13 then
  Edit1.Color := clAqua;

Cheers,
Phil.
0
petershaw9Author Commented:
I am sorry because I simplified my problem. The actual problem is that, I am using reportbuilder to produce a report. The reportbuilder has a component ppViewer that is a descendant of TPanel. The report is show on the ppViewer. The ppViewer does not have event that I can use to control the scrollbar, but it has the scrollbox property that I can use. So I wish to use arrow keys and get wm_keydown message, then use scrollbox property to control the scrollbars. I test the procedure on a blank form. The procedure is procedure Tform1.aaa(var msg : Tmessage);
begin
  if msg.WParam = VK_Return then
    showmessage('work');
end;

It works. But when I add a control like a panel or edit box then it doesn¡¯t work. That is my actual problem. I haven¡¯t test Hubdog¡¯ code. But I want to know what the ¡®handled¡¯ is used for. And you, experts, can tell me what is the problem with my code?

Merry Christmas & Happy New Year!


PeterShaw9
0
petershaw9Author Commented:
I follow Hubdog suggestion. It works.
procedure TfrmRepCltInc.CtrlScrollBar(var Msg: TMsg; var Handled: Boolean);
const iVertMove : Integer = 0;
begin
  if Msg.message=wm_keydown then
  begin
      if msg.WParam = VK_DOWN then
      begin
        inc(iVertMove, Round(ppViewer1.Scrollbox.vertscrollbar.range/50));
        ppViewer1.ScrollBox.VertScrollBar.Position := iVertMove;
        Handled := True;
      end else Handled := False;
  end;
end;

0
hubdogCommented:
because my suggestion so i think i will
mark my suggestion as answer.:)

Merry Christmas !


hubdog
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.