SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
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!

Weitere ähnliche Inhalte

Ähnlich wie Delphi L03 Forms and Input

06 win forms
06 win forms06 win forms
06 win formsmrjw
 
Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Mohammad Shaker
 
C++ Windows Forms L02 - Controls P1
C++ Windows Forms L02 - Controls P1C++ Windows Forms L02 - Controls P1
C++ Windows Forms L02 - Controls P1Mohammad Shaker
 
Delphi L07 Controls at Runtime P1
Delphi L07 Controls at Runtime P1Delphi L07 Controls at Runtime P1
Delphi L07 Controls at Runtime P1Mohammad Shaker
 
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 88Mahmoud Samir Fayed
 
360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex360|Flex Greenthreading In Flex
360|Flex Greenthreading In FlexHuyen Tue Dao
 
Flyte kubecon 2019 SanDiego
Flyte kubecon 2019 SanDiegoFlyte kubecon 2019 SanDiego
Flyte kubecon 2019 SanDiegoKetanUmare
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theorynickywalters
 
Os2 2
Os2 2Os2 2
Os2 2issbp
 
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 GoToru Furukawa
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowRachid Kherrazi
 
Behavior Driven Testing with SpecFlow
Behavior Driven Testing with SpecFlowBehavior Driven Testing with SpecFlow
Behavior Driven Testing with SpecFlowRachid Kherrazi
 

Ähnlich wie 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
 

Mehr von Mohammad Shaker

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 GraduateMohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game DevelopmentMohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesMohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - ColorMohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - TypographyMohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingMohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and ThreadingMohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSMohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsMohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsMohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and GamingMohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / ParseMohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesMohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and AdaptersMohammad Shaker
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieIndie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieMohammad Shaker
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to GamesIndie Series 01: Intro to Games
Indie Series 01: Intro to GamesMohammad Shaker
 

Mehr von 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
 

Kürzlich hochgeladen

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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...Drew Madelung
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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 organizationRadu Cotescu
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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.pdfsudhanshuwaghmare1
 
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 textsMaria Levchenko
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Kürzlich hochgeladen (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

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;