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 private2 FEgg: string;
3 FCount: Integer;
FCount holds a count of Keystrokes.
FEgg holds the Keystrokes string.
3.- Create two constants
4 const5 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 begin9 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 begin16 //Are the correct control keys down?17 if Shift = EE_CONTROL then18 begin19 //was the proper key pressed?20 if Key = Ord(FEgg[FCount]) then21 begin22 //was this the last keystroke in the sequence?23 if FCount = Length(FEgg) then24 begin25 //Code of the easter egg26 ShowMessage('Add your own code here!');
27 //failure - reset the count28 FCount := 1; {}29 end30 else31 begin32 //success - increment the count33 Inc(FCount);
34 end;
35 end36 else37 begin38 //failure - reset the count39 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!