delphi l01 intro

46
Mohammad Shaker mohammadshakergtr.wordpress.com Intro to Event-driven Programming and Forms with Delphi @ZGTRShaker 2010, 2011, 2012 Intro to Event-driven Programming and Forms with Delphi L01 - Introduction

Upload: mohammad-shaker

Post on 01-Jul-2015

792 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Delphi L01 Intro

Mohammad Shakermohammadshakergtr.wordpress.com

Intro to Event-driven Programming and Forms with Delphi@ZGTRShaker

2010, 2011, 2012

Intro to Event-driven Programming and Forms with Delphi

L01 - Introduction

Page 2: Delphi L01 Intro
Page 3: Delphi L01 Intro

About the Course

• Delphi 2007-2009• How to think like a programmer• Test Questions• You need to try your self, otherwise it won’t work out with

you (practice, practice, practice)

Page 4: Delphi L01 Intro

Course plan

• Introduction to Delphi• Introduction to IDE & Event Driven Programming• Start\Save\Open a project• Form design (design\runtime )• Delphi Components • Input Handling• Event handling• Files • Drawing (Canvas, Timer, etc.)• Instantiate Controls at Runtime

Page 5: Delphi L01 Intro

Delphi History• ‘ALGOL’* the first high-level language • ‘ALGOL’* > Pascal ‘Niklaus Wirth’**• the original definition of Pascal was published in 1971. • Pascal becomes the ‘FORMAL’ programming language.• Turbo Pascal 1.0 (November 1983) • Delphi in 1995 Was introduced for ‘Visual Programming’

• *ALGOL: Algorithmic language• ** Niklaus Wirth: (b. February 15, 1934) is a Swiss computer scientist, best

known for designing Pascal programming language, and for pioneering several classic topics in software engineering. In 1984 he won the Turing Award for developing a sequence of innovative computer languages.

Page 6: Delphi L01 Intro

Delphi History

• Pascal > Delphi• Borland > Pascal > Compiler > Delphi

Page 7: Delphi L01 Intro

Differences

• Interface: from “Console” to “Visual”.• All Applications need Visual Interaction.• IDE: (Integrated Development Environment)

Page 8: Delphi L01 Intro

Delphi Preferences & features

• OOP (Object Oriented Programming)• Applications: are build in the form of ‘forms’.• Components • Api functions ‘in Windows’.• 10 times faster compiler in comparison to other programming

languages.– Executive building files (exe) forms.– No DLL libraries like other programming languages (Dynamic Link

Library)– Database compatibility.

Page 9: Delphi L01 Intro

Now, let’s sneak peek

Page 10: Delphi L01 Intro

InstallCodeGear Delphi

Page 11: Delphi L01 Intro

What’s for today?

• Design time\Execution time (runtime)• Event-Driven Programming• Your first Project• Forms, Buttons• ShowMessage

Page 12: Delphi L01 Intro

Design time\Executing time

Page 13: Delphi L01 Intro

Programs executing

• Procedural Programming:– Sequential

• “Event-Driven” Programming:– Event

Page 14: Delphi L01 Intro

File Menu

• New > VCL forms Applications • open • Save

Page 15: Delphi L01 Intro
Page 16: Delphi L01 Intro
Page 17: Delphi L01 Intro

Open\Save a Project

• When saved.– first, “UNIT” is being saved – Then, the “PROJECT”

• File > Save as (Pas file is saved)• File > Save project as (dpr is saved)• “exe.” file is formed in running time.

Page 18: Delphi L01 Intro
Page 19: Delphi L01 Intro

Object inspector

Page 20: Delphi L01 Intro

Object inspector

• Properties: like width, color, etc.• Events: like pressing buttons, moving mouse, etc.

Page 21: Delphi L01 Intro

Properties

Page 22: Delphi L01 Intro

Events

Page 23: Delphi L01 Intro

Common Properties for all components

• Width, Height.• Top, left.• ‘Hint’ adding & showhint.• Visible.• Enabled.• Font.• Color.

Page 24: Delphi L01 Intro

Common Events for all components

• Onclick• OnDoubleClick• OnMouseMove• OnDragDrop• OnCreate • OnClose• Rest of them

Page 25: Delphi L01 Intro

Note that

• All the above properties & events can be modified at design time or runtime.

Page 26: Delphi L01 Intro

Event Handling Live Example

Page 27: Delphi L01 Intro

Tool palette.. components

Page 28: Delphi L01 Intro

Tabs

Page 29: Delphi L01 Intro

FormsWindows Applications forms

Every “form” has a corresponding “unit”

Page 30: Delphi L01 Intro

Forms properties

• All the following properties are ‘boolean’s:– BiSystemMenu:

• All three buttons disappear.

– BiMinimize: • to taskbar minimization.

– BiMaximize: • resize button.

– BiHelp: • ’?’ button.

• Position: the place the form will appear on the screen. • Icon: the style of the form’s icon.

– You can browse it from your PC images & pics.

Page 31: Delphi L01 Intro

Forms events

• OnClose• OnMouseClick• OnHold• OnCreate• OnResize• OnMouseWheelUp

Page 32: Delphi L01 Intro

Buttons

• Adding a button to our project

Page 33: Delphi L01 Intro

Button properties• Name: the one we use in code (we can’t write in Arabic here.) • Caption: the “Visual” name that will appear to the client. (we can

write in Arabic here) *• Top\left: parametric variables indicate the position of the

component in the form.• Fonts: color\volume & type of the written “Caption” design.• Hint: showing a ‘hint’ when the cursor (mouse) stop on the ‘button’.• Show Hint: shows the written hint above. • Visible Enabled• Tab Order• etc._________________________________*Delphi is Arabic compatible

Page 34: Delphi L01 Intro

Button Events

• OnClick• OnMouseMove• OnKeyPress• etc.

Page 35: Delphi L01 Intro

Button Events

• Let’s have a quick sneak on the code• Create a new form• Place a “Button” named “KeKe” in it.:D• Double click on the button• See where you are now • Test it

Page 36: Delphi L01 Intro

ShowMessageCtrl + Space

Page 37: Delphi L01 Intro

Button Events

Events + Properties

Page 38: Delphi L01 Intro
Page 39: Delphi L01 Intro
Page 40: Delphi L01 Intro

Test it

Before Clicking After Clicking

Page 41: Delphi L01 Intro

ShowMessage

• The name of the application's executable file appears as the “caption” of the message box.

• Msg parameter is the message string that appears in the message box.

• Code example:

Var worked:boolean;

If (not(Worked)) thenShowMessage (‘Cmon Work ’);

Page 42: Delphi L01 Intro
Page 43: Delphi L01 Intro

ShowMessage

procedure TForm1.Button1Click(Sender: TObject);

var b: boolean;

begin

b:= false;

if (not(b)) then

begin

ShowMessage('Hi There ');

end;

end;

Page 44: Delphi L01 Intro

ShowMessage

After clicking the button

Page 45: Delphi L01 Intro

References

• ‘Delphi’ Help • Delphibasics.co.uk• Delphi Books

Page 46: Delphi L01 Intro

See you!