MPL Documentation

Modern Pascal Introduction

Modern Pascal is used in 4 primary areas of development.
  1. Server-side Scripting
    This was the original focus of Modern Pascal, allowing you to extend your web servers capabilities through scripting. The server-side engine is an Apache Module, giving it the tightest integration to the Apache Web Server. This module, is available in embedded or enterprise server. Embedded runs the script as if Modern Pascal was built-in to Apache, whereas, the Enterprise edition communicates to the Celerity script engine using an XML protocol. This design was inspired by ColdFusion (originally my Allaire), allowing your web server hardware to be inexpensive, and focus on accepting connections and returning data. While all business intelligence operates on a more robust server which can optionally cluster to other Celerity servers in the same or different data centers. The Enterprise Edition has been managing a 16 data center cluster for one of the most popular 24 video chat apps.
  2. Command line Scripting
    You can make operating system utilities which do not need a web server or web browser to operate, nor a GUI desktop interface. While the Linux CLI (Command Line Interface) allows you to do extremely complex functionality, where Windows does not, Using Modern Pascal's mp CLI app, you can write command line applications, background disk utilities, etc. We have even ported Technojock's Turbo Toolkit v5.0 to native MP plug-in
  3. Desktop Applications
    Even though this was not a primary focus of Modern Pascal, you can extend the language with specially designed units (DLL's) that extend the grammar to interact with the operating system's GUI engine. We are currently evaluating if we should embed GTK2 support for cross-platform native GUI via our DLL units design. We actually use the next solution for our desktop projects - as it allows for cross-platform support without direct access to the native host's GUI engine.
  4. Standalone Server Scripting
    For Desktop applications, you can use client technology like TideSDK, WebKit, etc. to make a front-end that communicates to the localhost socket layer. The plus of this approach is code written for one operating system usually works with minimal to no code changes on all other supported operating systems. Our Standalone Server Scripting goes by the codename CodeRunner was designed to build larger server applications. CodeRunner handles all communications using my DXSock Server SDK Suite, threading, and scripting transparently to you, your scripts are called after the connection is established. Allowing you to quickly develop solutions like EMail, Web, Chat and even Game Servers. In 2016, CodeRunner was redesigned to support multiple ports and multiple scripts, making it perfect for all-in-one server development.
Modern Pascal follows the common structure of other Pascal dialects, making it perfect to run existing Turbo Pascal, Apple Pascal, Object Pascal, old Delphi and Free Pascal code. The Pascal language is a procedural programming language, designed in 1968 and published in 1970 by Niklaus Wirth and named in honor of the French mathematician and philosopher Blaise Pascal. Pascal runs on a variety of platforms, such as Windows, Mac OS, and various versions of UNIX/Linux.

This tutorial will give you great understanding of Pascal to proceed with Modern Pascal and other related frameworks etc. Modern Pascal itself supports a hybrid syntax, while staying true to Pascal, we have extended the grammar to support many C operators, C data types, etc.


Screenshot: 64bit CentOS

Audience

This tutorial is designed for Software Professionals who are willing to learn Pascal Programming Language in simple and easy steps. This tutorial will give you the understanding of Modern Pascal Programming concepts, and after completing this tutorial, you will be at an intermediate level of expertise from where you can take yourself to higher level of expertise.

Prerequisites

Before proceeding with this tutorial you should have an understanding of software basic concepts like: what is source code, a compiler, text editor and execution of programs, etc. If you already have an understanding on any other computer programming language, then it will be an added advantage to proceed.

Overview

Pascal is a general-purpose, high-level language that was developed for teaching programming as a systematic discipline and to develop reliable and efficient programs. Pascal offers several data types and programming structures. It is easy to understand and maintain Pascal programs.

Pascal has grown in popularity in the teaching and academia arena for various reasons:

Features of the Pascal Language

Pascal has the following features:
How Pascal is different from other languages:
Before we study the language, let us look at the bare minimum Pascal structure so we can take it as a reference in the upcoming language tutorials.

Pascal Program Structure

A Pascal program basically consists of the following parts (many are optional):
Every Pascal program generally has a header section, a declaration and an execution part structure in that order. Following format shows the basic syntax for a Modern Pascal program:
program HelloWorld;
uses display;

(* Here the main program block starts *)
begin
   WriteLn('Hello, World!'); { comment about this command }
   Readkey;
end.

Source Code Parts...

Looking at the above program source code:
To get a better understanding we will detail each of the basic building blocks of the pascal programming language.

Type Declarations

Type declarations provide you with the ability to extend or expand the variable types known by Modern Pascal. For example, a collection of characters is called a string, however, if you wanted to limit it to 20 characters maximum you could introduce a new string type of String[20]. When an identifier occurs on the left side of a type declaration, it's declared as a type identifier for the block in which the type declaration occurs.Type declarations are normally defined at the beginning of your code with the keyword type, followed by definitions of the variable types as follows:
type type_name1=existing_definition;  // "rename" a type for your better understanding
   type_name2=new_definition;         // add a new type definition to Modern Pascal
   type_name3=array_structure;        // simplify interaction with an array type
   type_name4=record_structure;       // introduce a type of multiple variables
   type_name6=class_structure;        // introduce a type with associated methods

Variables

Variables hold data which can be changed during the operation of your program. Variable definitions are normally defined at the beginning of your code with a var keyword, followed by the type of the variable. When you declare a variable, you must state its type. A variable's type circumscribes the set of values it can have and the operations that can be performed on it.
var variable1:variable_type;
   variable2:variable_type;
   variable3, variable4:variable_type;

Functions and Procedures

In Pascal, a Procedure is a set of instructions to be executed that do not return a value, and a Function is a procedure which returns a value. The code between the last begin and end in a program drives the logic of the program. In a very simple program, this section of code might be all you need. In larger, more complex programs, putting all your code here can make your program harder to read and understand-and more difficult to develop.

Procedures and functions let you divide the logic of a program into smaller, more manageable chunks, and are similar to subroutines in some other languages. All the action in a procedure or function occurs in the code between its begin and end just like in the main program block. Each of these segments of code performs a small, discrete task.

If you find your program does the same thing many times, you might want to put the logic into a procedure or function. You write the code in a procedure or function once and your program can use it as often as necessary. The definition of each follows:
Procedure Proc_Name(optional_parameters...);

Function Func_Name(optional_parameters...):Return_Value_Type;

Comments

Pascal is the only language which supports 3 different styles of comments. As we have discussed and shown on the Program Structure page, you can use (* ... *) for single or multiple lines of comment, you can use { ... } for single and multiple lines of comment too and // the double slash for comment the rest of the current line. Modern Pascal also supports the C style /* ... */ for single or multiple lines of comment. Making porting C code to Modern Pascal easier.
(* This is an example of a single line comment in this style *)

(* This is an example of using this style for multi-line
    comments as it will span multiple lines. *)

{This is an example of a single line comment in this style}

{This is an example of this style for multi-line
comments as it will span multiple lines.}

// Lastly, this is a single line comment - or
var a:Integer; // comment the rest of this line, or about this line.

/* Modern Pascal also supports C/Java/JavaScript style of comments
   which use the slash asterisk combination instead of parenthesis
   asterisk combination (like formal Pascal) */

Case Sensitivity

Pascal is not a case-sensitive language, which means you can write your variables, function and procedure in either case. Like A_Variable, a_variable and A_VARIABLE all have the same meaning in Pascal. It is a good writing habit though to be consistent as if the language was case-sensitive for working with certain tools and learning/using other programming languages which usually are case-sensitive.

Statements

The code section between begin and end contains statements that describe the actions the program can take and is called the statement part. Pascal programs and units are made of statements. Each statement specifies a task or job of the program. These jobs could be declarations, assignment, calculations, reading or writing data, comparisons, making logical decisions, transferring program flow control, etc. All statements end with a semicolon:
WriteLn('Hello, World!');
Ch:=Readkey;
if (Ch=#27) then WriteLn('Goodbye.');

Naming Convention

In Pascal, types, class names, constants, variables, function names and procedure names following a strict naming convention: The following are reserved characters and cannot be used except for their explicate functionality(s):