Best Windows Hosting

  • 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

  • Protecting E-mail Addresses on Webpages: Beware of using mailto protocol
    Placing an e-mail address on a Web page is a dangerous prospect nowadays. If the document on which the address appears generates even a medi...
  • Client Side State Management in ASP.NET
    State Management in done on client side as well as on server side in ASP.NET. In this article, we will just focus on clinet side state manag...
  • Simple Object Access Protocol
    SOAP is a simple XML-based protocol to let applications exchange information over HTTP. Simply, SOAP is a protocol for accessing a Web Servi...
  • Preloading Images: A trick to overcome delays in image-rich webpages loading
    One of the things that can really slow down the display of Web pages is an abundance of images, each one of which can contain the equivalent...
  • Frameset, Frame and IFrame Elements in HTML
    Frame Element With frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and...
  • Silver Bullets for Testing
    Know Our Application Don’t start testing without understanding the requirements. If we test without knowledge of the requirements, we will n...
  • What is DOM (Document Object Model): Tree and Node Structure of HTML Page
    The Document Object Model (DOM) defines a standard way for accessing and manipulating HTML documents. The DOM presents an HTML document as a...
  • 5 E-mail Etiquette You Must Know
    From memos and letters to answering machines, voice mail and now email, the last one is here to stay. Studies show that nearly two million e...
  • Online Music Degrees
    For those who want to pursue a music degree but find it difficult to do so because of time constraints, financial difficulties or physical l...
  • DOM Events: Mouse Events, Keyboard Events, Form Events, Frame Events and Touch Events
    Mouse Events 1. Click Event (onclick): The event occurs when the user clicks on an element. 2. Double Click Event ( ondblclick):  The event...

Categories

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

Blog Archive

  • ▼  2012 (155)
    • ►  September (64)
    • ▼  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