Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to add style to your application implementing an easter egg Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
14-Aug-03
Category
Others
Language
Delphi 2.x
Views
156
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jorge Abel Ayala Marentes

Many world class applications implement some easter egg to give its author(s) 
credit, so why not to use this feature in your own applications?

Answer:

An easter egg is some piece of code that executes only when the user uses some 
special keystrokes, they are used frequently to give credit to the author(s) of 
some program. 

For example in Delphi“s About box hold Shift + Alt and then type "team", you will 
expose an easter egg giving credit to Delphi Staff. 

To create your own easter egg take this steps: 

1.- Start a new Project 

2.- Create the following private fields: 

1   private
2   FEgg: string;
3   FCount: Integer;


FCount holds a count of Keystrokes. 
FEgg holds the Keystrokes string. 

3.- Create two constants 

4   const
5     EE_CONTROL: TShiftState = [ssCtrl, ssAlt];
6     EASTER_EGG = 'SECRET';


EE_CONTROL contains the control keys that must be down when the user types the 
EASTER_EGG string 

4.- In the OnCreate event of the form write 

7   procedure TForm1.FormCreate(Sender: TObject);
8   begin
9     FCount := 1;
10    FEgg := EASTER_EGG;
11  end;


5.- In the OnKeyDown event of the form write 
12  
13  procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
14    Shift: TShiftState);
15  begin
16    //Are the correct control keys down?
17    if Shift = EE_CONTROL then
18    begin
19      //was the proper key pressed?
20      if Key = Ord(FEgg[FCount]) then
21      begin
22        //was this the last keystroke in the sequence?
23        if FCount = Length(FEgg) then
24        begin
25          //Code of the easter egg
26          ShowMessage('Add your own code here!');
27          //failure - reset the count
28          FCount := 1; {}
29        end
30        else
31        begin
32          //success - increment the count
33          Inc(FCount);
34        end;
35      end
36      else
37      begin
38        //failure - reset the count
39        FCount := 1;
40      end;
41    end;
42  end;


6.- Finally set the Form“s KeyPreview property to true. 

Now you just have to replace the ShowMessage with Something more creative, use your imagination!

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC