Cheap Hosting Domain Names

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 27 August 2012

OnShortCut event of Delphi XE2 Forms

Posted on 05:00 by Unknown

This article is about OnShortCut event of Delphi Forms. Lets discuss the requirement first.

Requirement: Assme that I have two Delphi forms in my project (MyForm1 and MyFrom2). Now my requirement is that, if I am on MyForm1 and press ESC, I should go to MyForm2 and vice versa.

Consider the code of MyForm1:

unit uf_MyUnit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.ComCtrls;

type
  TfMyUnit1 = class(TForm)
    procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);  
  private
  
  public

  end;

var
  fMyForm1: TfMyUnit1;

implementation

uses uf_MyUnit2;

{$R *.dfm}

procedure TfMyUnit1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
   case Msg.CharCode of
      27 : begin
             Handled := true;
             fMyForm2.Show;
             fMyForm1.Close;
           end;
   end;
end;

end.

Explanation: Remember to add FormShortCut function on the OnShortCut event of the form. By adding this function on the OnShortCut event of the form, this function will immediately gets fired when any key is pressed. '27' is the keycode for ESC key. So when ESC key is pressed fMyForm2 is displayed and current form is closed.

Similar is the code for MyForm2:

unit uf_MyUnit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.ComCtrls;

type
  TfMyUnit2 = class(TForm)
    procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);  
  private
  
  public

  end;

var
  fMyForm2: TfMyUnit2;

implementation

uses uf_MyUnit1;

{$R *.dfm}

procedure TfMyUnit2.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
   case Msg.CharCode of
      27 : begin
             Handled := true;
             fMyForm1.Show;
             fMyForm2.Close;
           end;
   end;
end;

end.

Email ThisBlogThis!Share to XShare to Facebook
Posted in Delphi | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Online Religion Degrees
    Religion plays a major role in the historical, political, and cultural life of our societies. If you are fascinated by belief systems, consi...
  • How to create dynamic tables in HTML using javascript at runtime?
    In this tutorial, you will come to know how to create dynamic tables in HTML. There are some situations when you don't know the contents...
  • Online Economics Degrees
    Economists research and analyze economics, or the way people choose to use their resources to produce goods and services. Economists typical...
  • Online Advertising Degrees
    The objective of any business firm is to market and sell its products or services profitably. In small firms, the owner or chief executive o...
  • Online Geography Degrees
    With the growth of online colleges and universities, geography degrees online have gained immense importance. Geography degrees online can b...
  • Online DBA (Database Administrator) Degrees
    Database managers keep vital information organized.  With a database technology degree, you may find yourself organizing customer informatio...
  • Online Social Science Degrees
    Social science covers a broad range of fields: behavioral science, history, economics, geography, political science, women''s studie...
  • Difference between page_init, page_load and page_prerender events
    page_init This event is the first event to occur when an ASP.NET page is executed. This is the event where you should be performing any init...
  • Online BCA Degrees
    The boom in the IT industry has opened up plenty of job opportunities for computer professionals. As a result, computer application courses ...
  • Online Professional Degrees
    Going back to get more education can be a difficult, time consuming and sometimes impossible proposition. But with new advances in virtual t...

Categories

  • AJAX
  • C++
  • CSS
  • Delphi
  • DOTNET
  • HTML
  • Javascript
  • jQuery
  • Management
  • Online Degrees
  • Oracle
  • Others
  • Phonegap
  • PHP
  • Unix
  • XML

Blog Archive

  • ▼  2012 (180)
    • ►  September (89)
    • ▼  August (11)
      • How important is grooming in professional life?
      • 7 Questions to Ask in Your Appraisal Meeting
      • 5 ways to handle workload at your workplace
      • Interview Tips: How to get prepared for an interview?
      • Phonegap on Blackberry: 2 Programming Tips
      • How to use FindComponent function in Delphi XE2?
      • How to use TADOTable in Delphi XE2?
      • How to use TADOQuery in Delphi XE2?
      • OnShortCut event of Delphi XE2 Forms
      • Phonegap: An amazing combination of HTML5, CSS3 an...
      • Delphi 2010, Delphi XE and XE2: A comparison of fe...
    • ►  July (4)
    • ►  June (3)
    • ►  May (25)
    • ►  April (48)
Powered by Blogger.

About Me

Unknown
View my complete profile