ISM 2110 Programming for Business Applications Lecture 2 - Section 2 Delphi and Object Pascal Basic By Tony Chun-Kuen WONG Tutorial after 12/09/2002.

Slides:



Advertisements
Similar presentations
Programming Paradigms and languages
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Chapter 2: Introduction to C++.
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
CPS120: Introduction to Computer Science Lecture 8.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
CIS Computer Programming Logic
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
1 Procedures Blocks of code which can be called from anywhere in a program Enable us to avoid needless repetition of the same code Can take parameters.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CPS120: Introduction to Computer Science
Lecture #5 Introduction to C++
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Lection №5 Modern integrated development environment.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Applications Development
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Lecture 3 Introduction to Computer Programming CUIT A.M. Gamundani Presentation Layout from Lecture 1 Background.
CPS120: Introduction to Computer Science Variables and Constants.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter 3 AS3 Programming. Introduction Algorithms + data structure =programs Why this formula relevant to application programs created in flash? The.
Controlling Program Flow with Decision Structures.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
VBA - Excel VBA is Visual Basic for Applications
Chapter 2: Introduction to C++
The CONST definition CONST Pi = , City = ‘New York’;
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
2.1 Parts of a C++ Program.
WEB PROGRAMMING JavaScript.
C++ Data Types Data Type
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
CHAPTER FOUR VARIABLES AND CONSTANTS
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
Focus of the Course Object-Oriented Software Development
Chapter 2: Introduction to C++.
Variables and Constants
Presentation transcript:

ISM 2110 Programming for Business Applications Lecture 2 - Section 2 Delphi and Object Pascal Basic By Tony Chun-Kuen WONG Tutorial after 12/09/2002

Object Pascal Language  New Term: An object, like components described earlier, is a binary piece of software that performs a specific programming task.  An object reveals to the user (the programmer using the object) only as much of itself as needed; therefore, using the object is simplified. All internal mechanisms that the user doesn't need to know about are hidden from sight. All this is included in the concept of object- oriented programming.

Pascal Units  New Term: A unit is a text file that can be compiled into a module of code.  A Delphi GUI application will contain at least two units. The project source unit contains the project source code. Project source code units have an extension of DPR.  The second type of unit that a Delphi GUI application always has is the main form's unit. A form unit, as its name implies, is a source code unit with an associated form. This type of unit has a filename extension of PAS.

Project source for a default delphi project 01: program Project1; 02: 03: uses 04: Forms, 05: Unit1 in `Unit1.pas' {Form1}; 06: 07: {$R *.RES} 08: 09: begin 10: Application.Initialize; 11: Application.CreateForm(TForm1, Form1); 12: Application.Run; 13: end.

Blank Pascal Unit unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} end.

Anatomy of a Delphi Unit  The uses list is a list of external units that this unit references  The interface section is the section of a unit in which identifiers exported from this unit are declared. An exported identifier is one that can be accessed by other units in the project.  The implementation section of a unit is the section that contains the actual code for the unit.

The const Keyword  A unit can optionally have one or more const sections. The const section is designated with the const keyword. The const section describes a list of variables that are known as constants.  A constant is an identifier that cannot change.

Example unit Unit1; interface const AppCaption = ‘My Funny Program 1.0’; procedure DoSomething; implementation const BaseX = 20; BaseY = 200; procedure DoSomething; begin { Code for DoSomething goes here. } end;

The type Keyword New Term: The type keyword is used to declare new types that your program will use. example type TMyArray = array [0..19] of Byte;

The var Keyword New Term: The var keyword is used to declare a section of code in which variables are declared.  There are several places you can declare a var section. You can have a var section at the unit level, you can have a var section for a procedure or function, or both. You can even have multiple var sections in a unit.

unit Unit1; interface type TMyArray = array [0..19] of Byte; const AppCaption = ‘My Funny Program 1.0’; var X : Integer; MyArray : TMyArray; procedure DoSomething; implementation const BaseX = 20; BaseY = 200; procedure DoSomething; begin { Code for DoSomething goes here. } end; end.

Comments in code  Comments are lines of text in your source code that are there for documentation purposes. Comments can be used to describe what the code does, to supply copyright information, or simply to make a note to yourself or other programmers.

Comments can be designated in as many as three different ways. The following are all valid comments lines: { Don't forget to free this memory! } { TonyCalculator.Pas Ver 3.01 Copyright (c) TurboTony Software } (* Jason needs to fix this section of code *) // This is really good code! { This code needs to be reworked later }

 NOTE: If you work in a team programming environment, you might have to read your coworkers' code and vice versa. Concise comments in the code can save hours of time for any programmer who has to read and maintain another programmer's code. Even if you work in a single-programmer environment, commenting your code is a good idea. You'd be surprised how quickly you forget what code you wrote is supposed to do. Good code commenting can save you and your coworkers hours of time, so don't forget to comment your code!

Variables  Variables have to be declared before they can be used. You declare a variable in a special section of code designated with the var keyword, as described earlier example 1 var X : Integer; { variable X declared as an integer variable } Y : Integer; { variable Y declared as an integer variable } example 2 procedure TForm1.Test; var S : string; begin S := `Hello World!'; Label1.Caption := S; end;

Example 3 X := 100; { ‘X’ now contains the value 100 } X := X + 50; { ‘X’ now contains the value 150 } Y := 150; { ‘Y’ now contains the value 150 } X := X + Y; { ‘X’ now contains the value 300 } Inc(X); { Increment. ‘X’ now contains the value 301 } A variable is a location set aside in computer memory to contain some value.

Object Pascal Data Types New Term: In Object Pascal, a data type defines the way the compiler stores information in memory. Declaring a Variable In Object Pascal, you must declare a variable's type before you can use the variable  Some data types are signed and some are unsigned. A signed data type can contain both negative and positive numbers, whereas an unsigned data type can contain only positive numbers.

 Data TypeSize in BytesPossible Range of Values  ShortInt1-128 to 127  Byte10 to 255  Char10 to 255 (same as Byte)  WideChar20 to 65,535 (same as Word)  SmallInt2-32,768 to 32,767  Word20 to 65,535  LongInt4-2,147,483,648 to 2,147,483,647  Int648-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807  Integer4Same as LongInt

 Data TypeSize in BytesPossible Range of Values  Cardinal40 to 2,147,483,647  Single41.5 * to 3.4*  Double85.0 * to 1.7 *  Real488same as Double  Extended103.4 * to 1.1 *  Comp8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807  Currency8-922,337,203,685, to 922,337,203,685,  Boolean1True or False  Variant16Varies

Commonly used Operators  OperatorDescriptionExample  Mathematical Operators  +Additionx := y + z;  -Subtractionx := y - z;  *Multiplicationx := y * z;  /Real number divisionx := y / 3.14;  divInteger divisionx := y div 10;  Assignment Operators  := Assignment x := 10;

 OperatorDescriptionExample  Logical Operators  and Logical AND if (x = 1) and (y = 2) then...  or Logical OR if (x = 1) or (y = 2) then...  Equality Operators   = Equal to if (x = 10) then...  <> Not equal to if (x <> 10) then...  < Less than if (x < 10) then...  > Greater than if (x > 10) then...  <= Less than or equal to if (x <= 10) then...  >= Greater than or equal to if (x >= 10) then...

example If (started = True) and (X > 30) then z := x=y;

Programming using Delphi

A sample for Loop 1. Begin with a new application. 2. Place a button on the form. 3. Locate the Memo component on the Standard tab of the Component palette (it should be just to the left of the Button component). Click the button, and then click on the form. A memo will be placed on your form. 4. Make the memo larger by dragging the black sizing rectangle in the lower-right corner of the memo. 5. Double-click the button to create an OnClick event handler for the button. Enter code so that the event handler looks like this:

A sample for Loop procedure TForm1.Button1Click(Sender: TObject); var I : Integer; begin Memo1.Lines.Clear; for I := 0 to 5 do Memo1.Lines.Add(‘This is iteration ‘ + IntToStr(I)); Memo1.Lines.Add(‘'); for I := 5 downto 0 do Memo1.Lines.Add(‘This is iteration ‘ + IntToStr(I)); end;