SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
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
“Unit”s
Dividing your programs into district “unit”s is useful for
organizing your project
Peek on our “Delphi code area”
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
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.
Switching between forms
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.
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
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
Switching between forms
Test it live
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;
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;
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;
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;
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;
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;
Let’s exercise!
See you!

Más contenido relacionado

Similar a Delphi L03 Forms and Input

Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2
Mohammad Shaker
 
Delphi L07 Controls at Runtime P1
Delphi L07 Controls at Runtime P1Delphi L07 Controls at Runtime P1
Delphi L07 Controls at Runtime P1
Mohammad Shaker
 
Os2 2
Os2 2Os2 2
Os2 2
issbp
 
Behavior Driven Testing with SpecFlow
Behavior Driven Testing with SpecFlowBehavior Driven Testing with SpecFlow
Behavior Driven Testing with SpecFlow
Rachid Kherrazi
 

Similar a Delphi L03 Forms and Input (20)

06 win forms
06 win forms06 win forms
06 win forms
 
Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2
 
C++ Windows Forms L02 - Controls P1
C++ Windows Forms L02 - Controls P1C++ Windows Forms L02 - Controls P1
C++ Windows Forms L02 - Controls P1
 
Delphi L01 Intro
Delphi L01 IntroDelphi L01 Intro
Delphi L01 Intro
 
Delphi L07 Controls at Runtime P1
Delphi L07 Controls at Runtime P1Delphi L07 Controls at Runtime P1
Delphi L07 Controls at Runtime P1
 
The Ring programming language version 1.3 book - Part 54 of 88
The Ring programming language version 1.3 book - Part 54 of 88The Ring programming language version 1.3 book - Part 54 of 88
The Ring programming language version 1.3 book - Part 54 of 88
 
360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex
 
Variables and constants
Variables and constantsVariables and constants
Variables and constants
 
Flyte kubecon 2019 SanDiego
Flyte kubecon 2019 SanDiegoFlyte kubecon 2019 SanDiego
Flyte kubecon 2019 SanDiego
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theory
 
Os2 2
Os2 2Os2 2
Os2 2
 
My client wanted their apps synced, and I made it with Go
My client wanted their apps synced, and I made it with GoMy client wanted their apps synced, and I made it with Go
My client wanted their apps synced, and I made it with Go
 
Intro to MIDP Development
Intro to MIDP DevelopmentIntro to MIDP Development
Intro to MIDP Development
 
Os2
Os2Os2
Os2
 
How to make a game app.pptx
How to make a game app.pptxHow to make a game app.pptx
How to make a game app.pptx
 
Ipc feb4
Ipc feb4Ipc feb4
Ipc feb4
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
 
Behavior Driven Testing with SpecFlow
Behavior Driven Testing with SpecFlowBehavior Driven Testing with SpecFlow
Behavior Driven Testing with SpecFlow
 
delphi-interfaces.pdf
delphi-interfaces.pdfdelphi-interfaces.pdf
delphi-interfaces.pdf
 
delphi-interfaces.pdf
delphi-interfaces.pdfdelphi-interfaces.pdf
delphi-interfaces.pdf
 

Más de Mohammad Shaker

Más de Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieIndie Series 03: Becoming an Indie
Indie Series 03: Becoming an Indie
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to GamesIndie Series 01: Intro to Games
Indie Series 01: Intro to Games
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Delphi L03 Forms and Input

  • 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.
  • 3. “Unit”s Dividing your programs into district “unit”s is useful for organizing your project
  • 4. Peek on our “Delphi code area”
  • 5. 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
  • 6. 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.
  • 8. 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.
  • 9. 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
  • 10. 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
  • 12. 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;
  • 13. 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;
  • 14. 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;
  • 15. 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;
  • 16. 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;
  • 17. 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;