High Level Languages - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

High Level Languages

Description:

Web:: www.cs.nott.ac.uk/~jog/HLL. 3. High Level Languages. Here we go... By Reisdorph (available at amazon.co.uk - 24hr delivery - accessible through the ... – PowerPoint PPT presentation

Number of Views:73
Avg rating:3.0/5.0
Slides: 55
Provided by: scie205
Category:

less

Transcript and Presenter's Notes

Title: High Level Languages


1
High Level Languages
2
Here we go.
  • Course is split up into 3 sections
  • Delphi (Windows Programming)
  • Perl (Server Programming)
  • PHP (Web Programming)
  • Delphi PHP taught by James Goulding.
  • Perl taught by Chris Coleman.
  • Web www.cs.nott.ac.uk/jog/HLL

3
Here we go.
  • Lectures
  • Wednesday 13.00 (C3)
  • Friday 09.00 (LT2)
  • Labs
  • Monday 16.00 18.00 (A32)
  • Coursework
  • 1 coursework for each section
  • Total of 3 courseworks, each with identical
    weight
  • NO EXAM!

4
High Level Languages
  • Section 1
  • Delphi

5
Book List
  • A booklist can be found on the course Web page.
  • The recommended text for Delphi is
  • SAMS Teach Yourself Borland
  • Delphi 5 in 21 Days
  • By Reisdorph (available at amazon.co.uk - 24hr
    delivery - accessible through the HLL Web Page).

6
What are HLL?
  • Low Level Languages
  • - Machine Code, Assembler
  • Mid Level Languages
  • - Java, C, Pascal, C
  • High Level Languages
  • - Visual Basic, CBuilder, Delphi

7
Graphical User Interfaces
  • GUIs require complicated code and are incredibly
    labour intensive
  • Almost impossible to program GUIs using
    procedural programming
  • Easier using OO techniques, but by no means
    simple, and very intimidating.
  • RAD systems were created to deal with this
    problem.

8
  • PASCAL!

9
What HLL are on offer?
  • Visual Basic
  • Visual C
  • Visual J
  • CBuilder
  • JBuilder
  • Delphi

10
What Is Visual Basic?
  • Widely Used Microsoft RAD suite
  • Evolved from MS Basic
  • Visual Front End
  • Heavily modified Basic as underlying language
  • Pros Very Popular
  • Some Object Orientation
  • Extensive Database Capability
  • Cons One Major drawback

11
What Is Visual Basic?
  • BASIC is absolute rubbish

12
What are Visual C/J?
  • Microsofts RADs for C and Java
  • Use slightly modified versions of C and an
    incredibly incompatible version of Java.
  • Most widely used languages for creating
    professional
  • Windows applications
  • Used to write apps such as Word and Excel.
  • Microsofts environments are VERY clumsy

13
What Is Delphi?
  • Delphi is a RAD product, written by Borland.
  • You can create Win32 console GUI programs for
    Windows very quickly and easily.
  • You can use drag-and-drop techniques to create
    the user interface to a program.
  • Many debugging tools
  • Fully Object Orientated
  • Extensive Database capability
  • True Windows Compiler hence very efficient
  • The language underlying Delphi is an OO version
    of

14
  • PASCAL!

15
The Delphi IDE
  • You will find a copy of Delphi 5 on the computers
    in the IT Terminal Room (A32).
  • This program provides you with the Delphi
    integrated development environment (IDE), used to
    produce your Delphi applications.
  • The Delphi IDE is divided into 3 parts
  • Toolbars Component Palette
  • Object Inspector
  • Delphi Workspace

16
The Delphi IDE
17
Toolbars Component Palette
  • The toolbars allow you to access tasks such as
    opening, saving and compiling objects.
  • The component palette contains a wide array of
    components that you can drop onto your forms,
    e.g. buttons, text labels, etc.
  • A component is a self-contained binary piece of
    software that performs some specific predefined
    function.
  • They are divided into groups. To place a
    component on a form just choose it and click
    where you want it to appear on your form.

18
The Object Inspector
  • The object inspector is on the left side of the
    Delphi IDE.
  • Use the object inspector to modify a components
    properties and events.
  • A component property controls how the component
    operates, e.g. color property.
  • The events tab contains a list of events for a
    component. Events occur as the user interacts
    with a component. You write the event handling
    code.

19
The Delphi Workspace
  • The workspace initially displays the Form
    Designer. The Form Designer enables you to create
    forms.
  • A form might be the programs main window, a
    dialog box or any other type of window.
  • Behind the Form Designer is the Code Editor. This
    is where you type the code when writing your
    programs.

20
Object Pascal Language
  • Before you can learn the RAD features of Delphi,
    you need to learn the basics of the Object Pascal
    language.
  • Object Pascal forms the backbone of Delphi, and
    is obviously based heavily on Pascal, which was
    taught in Semester 1 to MA students in the ICP
    module.
  • I will provide an overview of the Object Pascal
    language. Extra reading may be necessary for a
    complete understanding of the language.

21
  • PASCAL!

22
History of Pascal
  • In 1994, Borland began working on a RAD tool
    called Delphi.
  • Borland needed to decide on a programming
    language that would be the heart of the system.
  • Since they were the only vendor of a Pascal
    compiler, they had much control over changes to
    the language.
  • They developed a new language, called Object
    Pascal, essentially their latest update to Turbo
    Pascal, and packaged it in Delphi.

23
Is Pascal Dead?
  • Clearly Not Pascal is still widely used in
    various new guises.
  • It is a vital part of Delphi, which is still a
    prolific RAD.
  • Only recently Component Pascal has been
    integrated into the new Microsoft .net
    environment, alongside C. Interestingly there is
    no place for Java.

24
Why has it survived?
  • It has a large user base
  • It is a very robust language (not case sensitive)
  • It is very easy to debug.
  • It is efficient.
  • It is very powerful, featuring
  • - full object orientation
  • - dynamic memory allocation
  • - pointers

25
Object-Oriented Programming
  • An object reveals to the user only as much as is
    needed, hence using an object simplifies
    programming.
  • Internal mechanisms of an object are hidden from
    the user. This is especially notable for objects
    that control a graphical interface.
  • Objects and classes will be discussed later this
    section.

26
Pascal Units
  • A unit, in Pascal, is a text file that can be
    compiled into a module of code. It contains
    Pascal language code, written by the programmer.
  • A Delphi application consists of at least two
    units.
  • A Project Source Unit contains project source
    code. It is not usually edited manually (not
    recommended either). Has file extension .DPR.

27
Pascal Units
  • A Form Unit contains the source code for a
    particular form in your application. It has
    extension .PAS.
  • There is always at least one form unit, in a
    Delphi application, representing the main form.
  • There are also units that contain only source
    code this is library code.

28
Anatomy of a Unit
  • The project source for a default Delphi unit
  • program Pop_Rivals
  • uses
  • Forms,
  • Unit1 in GirlsAloud.pas Form1
  • R .RES
  • begin
  • Application.Initialize
  • Application.CreateForm(TForm1, Form1)
  • Application.Run
  • end.

29
Project Source
  • The program keyword identifies the unit as a
    programs main source unit.
  • The uses keyword specifies the various other
    units that are needed to compile the program.
  • The R .RES is called a compiler directive
    which tells Delphi to include project resources.
  • The main code is between begin and end.
  • The main code initialises, creates and runs the
    application (Details not necessary).

30
A Blank Pascal Unit
  • unit Unit1
  • Interface
  • Implementation
  • end.
  • The start of a unit always has the unit keyword
    followed by the units name.
  • It always ends with an end keyword terminated by
    a full-stop (.)

31
The Interface Section
  • The interface keyword marks the start of the
    Interface Section of a unit.
  • The interface section is the section 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 end of the interface section is marked by the
    implementation keyword (see next slide).

32
The Implementation Section
  • The implementation section of a unit is the
    section that contains the actual code for the
    unit.
  • In essence, the interface is where you declare a
    function and the implementation is where you
    define that function.

33
Example
  • A unit with a public function
  • unit Unit1
  • interface
  • procedure javaIsRubbish
  • implementation
  • procedure javaIsRubbish
  • begin
  • Code for javaIsRubbish goes here
  • end
  • end.

34
The const keyword
  • The const section of a unit is where you would
    declare all the constants to be used in that
    unit.
  • ...
  • interface
  • const
  • AppCaption My Program
  • procedure DoSomething
  • implementation
  • ...
  • A const in the interface section is available to
    other units.

35
The var keyword
  • The var keyword is used to declare a section of
    code in which variables are declared.
  • A var section can be declared at different levels
    of scope at the unit level, in a procedure or in
    a function, e.g.
  • var
  • X Integer
  • MyArray TMyArray

36
Comments in Code
  • Comments are placed between curly braces.
  • This may be a little confusing for any Java or
    C programmers in the room! e.g.
  • this is a comment on one line
  • this is a comment
  • and it is on more than
  • one line

37
Object Pascal Techniques
  • Variables
  • Operators
  • Arrays
  • Strings
  • Decisions
  • Loops

38
1. Variables
  • Variables are declared in the var section
    (discussed earlier).
  • Variables can be declared within functions
  • var
  • S string declaration
  • I integer
  • begin
  • S Hello World! assignment
  • Label1.Caption S
  • end

39
Variable Types
  • There are various variable types available

40
2. Object Pascal Operators
  • Operators are similar to in other languages
  • Addition x y z
  • Subtraction x y z
  • Multiplication x y z
  • Real number division x y / 3.14
  • Integer division x y div 10
  • Logical AND if (x1) and (y2) then
  • Logical OR if (x1) or (y2) then

41
Object Pascal Operators
  • More operators
  • Equal to if (x10) then
  • Not equal to if (xltgt10) then
  • Less than if (xlt10) then
  • Greater than if (xgt10) then
  • Less than / equal to if (xlt10) then
  • Greater than / equal to if (xgt10) then

42
Converting Between Data Types
  • Object Pascal performs conversion between data
    types when possible.
  • However, when converting an integer to a string,
    the following function is useful
  • var
  • X SmallInt
  • begin
  • X 3200
  • Label1.Caption IntToStr(X)
  • end

43
3. Arrays
  • An array is declared as follows
  • var
  • MyArray array0..4 of Integer
  • This array contains the individual elements
    myArray0, myArray1, myArray2, myArray3,
    myArray4.

44
4. Strings
  • Strings are dynamically allocated memory in
    Delphi. To declare a string use
  • var
  • S string dynamically allocated string
  • To get the length of a string use the Length
    function.

45
Concatenating Strings
  • Strings can be concatenated
  • var
  • S1 string
  • S2 string
  • begin
  • S1 James
  • S2 Goulding
  • Label1.Caption S1 S2
  • end

46
More on Strings
  • To access individual elements of a string, treat
    the string as a character array. However, the
    array starts at index 1, not 0.
  • You can also compare strings using the usual set
    of operators , ltgt, lt, gt, lt, gt.
  • There are many string manipulation functions
    available. You can look them up in a Pascal or
    Delphi reference book, or try the on-line help in
    the Delphi RAD environment.

47
5. Decisions
  • The structure of an if statement in Pascal is as
    follows

48
Switch Statements
  • Switch statements look like this example
  • case expression of
  • value_1 statements_1
  • value_2 statements_2
  • ...
  • value_n statements_n
  • else
  • begin
  • end
  • end

49
6. Loops
  • The syntax of the For loop in Pascal is
  • for initial_value to end_value do begin
  • statements
  • end
  • For example
  • for I 0 to 9 do begin
  • Memo1.Lines.Add(Iteration IntToStr(I))
  • end

50
The While Loop
  • An example while loop looks like this
  • var
  • X Integer
  • begin
  • X 0
  • while X lt 1000 do begin
  • X DoSomeBoringCalculation
  • DoMoreBoringStuff
  • end
  • ... more code
  • end

51
The Repeat Loop Statement
  • The repeat loop repeatedly executes a block of
    code indicated by statements as long as the
    conditional expression cond_expr is False.
  • repeat
  • statements
  • until cond_expr

52
Continue Break
  • The continue procedure is used to force program
    execution to the bottom of the loop, skipping any
    statements that come after it.
  • The break procedure is used to halt execution of
    a loop prior to the loops normal test condition
    being met.
  • The exit procedure causes the whole program to
    terminate if it is called within the main program
    block.

53
Useful Functions
  • Inc(A) will increase the value of A by 1. This is
    similar to A in Java.
  • Dec(A) will decrement the value of A by 1.
  • Pred(A) will return the value of the predecessor
    to A. So if A is 10 it will return 9.
  • Succ(A) will return the value of the successor to
    A.

54
On-line Tutorials
  • Delphi is too big to teach in 6 lectures
  • You will be required to do some form of
    self-learning and practicing outside of lectures.
  • I will link some Borland on-line tutorials to the
    course Web site for you to look at. There will
    also a link to the ICP module Web site and an
    Object Pascal Language Guide.
Write a Comment
User Comments (0)
About PowerShow.com