Your SlideShare is downloading. ×
Delphi L03 Forms and Input
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Delphi L03 Forms and Input

193

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
193
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Intro to Event-driven Programming and Forms with Delphi L03 – Forms and Input Mohammad Shaker mohammadshakergtr.wordpress.com Intro to Event-driven Programming and Forms with Delphi @ZGTRShaker 2010, 2011, 2012
  • 2. “Unit”s Dividing your programs into district “unit”s is useful for organizing your project
  • 3. Peek on our “Delphi code area”
  • 4. Peek on our “Delphi code area” unit Unit1; interface Name of the “unit” we are working in Libraries we can take functions & procedures from it uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} end. Types & classes Public Variables Here begins the “unit” implementation
  • 5. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin end; end.
  • 6. Switching between forms
  • 7. Switching between forms • Create a new “form” in our “current” project: – File (Menu) > new > form • Select the main application form: – Project (Menu) > Options > Forms > Main Form – select the “main” application form.
  • 8. Switching between forms • Linking forms: – Every form has its own “unit”: • Form1 > unit1.pas • Form2 > unit2.pas – If we want: • form1 to use form2, we add to unit1 (NOT THE CONTRARY): – uses unit2 • form2 to use form1, we add to unit2 (NOT THE CONTRARY): – uses unit1 – Watch out • for “Circular declaration” in interfaces – i.e: uses unit1 & uses unit2 at the same time in unit
  • 9. Switching between forms “Events & Properties” • Some Events: – – – – – Form1.hide; Form1.show; Form1.OnClose; Form1.OnCreate; Form1.Refresh; // imp. // imp. // imp. • Some Properties: – Design time: • Visible, Enabled, etc. // Design time – Runtime: • Form1.Visibe:= True/False; • Form1.Enabled:= True/False; // Runtime // Runtime
  • 10. Switching between forms Test it live
  • 11. KeyBoard Response “Event”s • Event (Code Sample): procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState); Begin if (key = VK_Right) then // code else if (key = VK_Left) then //code end;
  • 12. KeyBoard Response “Event”s • Event (1st Code Example): (KeyDown: Down) procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin Label1.Caption:='0'; if (key = VK_RIGHT) then label1.Caption:='1' else if (key=VK_LEFT) then Label1.Caption:='2' else if (key=VK_DOWN) then Label1.Caption:='3'; end;
  • 13. KeyBoard Response “Event”s • Event (2nd Code Example): (KeyDown: UP) procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin Label1.Caption:='0'; if (key = VK_RIGHT) then label1.Caption:='1' else if (key=VK_LEFT) then Label1.Caption:='2' else if (key=VK_DOWN) then Label1.Caption:='3'; end;
  • 14. KeyBoard Response “Event”s • Event (3rd Code Example): (KeyDown: Left) procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var bool1:boolean; begin bool1:=false; Label1.Caption:='0'; if ((key = VK_RIGHT) and (bool1=not(false))) then label1.Caption:='1' else if (bool1=false) then Label1.Caption:='2' else Label1.Caption:='3'; end;
  • 15. KeyBoard Response “Event”s • Event (4th Code Example): (KeyDown: Down) procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var bool1:boolean; begin bool1:=true; Label1.Caption:='0'; if ((key = VK_RIGHT) or (bool1=not(false))) then label1.Caption:='1' else if (key=VK_LEFT) then Label1.Caption:='2' else if (key=VK_DOWN) then Label1.Caption:='3'; end;
  • 16. KeyBoard Response “Event”s • Event (5th Code Example): (KeyDown: Down) procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var bool1:boolean; begin bool1:=true; Label1.Caption:='0'; if ((key = VK_RIGHT) and (bool1=not(false))) then label1.Caption:='1' else if (key=VK_LEFT) then Label1.Caption:='2' else if (key=VK_DOWN) then Label1.Caption:='3'; end;
  • 17. Let’s exercise!
  • 18. See you!

×