Friday, May 18, 2018

The structure of a Pascal file

First I like to talk about the structure of an Oxygene Pascal file, as it is somewhat different from other languages - it is even somewhat different from other Object Pascal dialects to fit better in the Microsoft Visual Studio environment.

In the picture below you see the structure, as you can see, the definition and implementation is strictly separated from each other. This way the structure of the class is always clear for the developer- a thing that is missing in most other languages.

Object Pascal file structure


The namespace is not a standard Object Pascal keyword. In other versions of Pascal, the keyword Unit is used here, but in .Net Unit has no meaning. That's why the namespace is used instead, as each class in .Net is in a namespace.

The keyword interface defines that the interface definitions follow - interface definitions are all type definitions within this files; classes, structures, enums, type aliases, and so on.

The uses section is a standard Object Pascal keyword, but is used for another purpose in Oxygene; In standard Object Pascal, the uses clause points to all files (units) that are needed for this unit to compile (in Visual Studio, you have the project references for this).
In Oxygen, the uses keyword is used to import namespaces, like Imports in VB.net or Using in C#. 
Other than in VB, only the types are imported, not the embedded Namespaces.
So If you have System.Collections in the uses, you can not write Generics.List ....
You have to add System.Collections.Generics, to be able to write List....

Next, a type definition follows (in this example a class). You can define as may types as you want.

After the type definitions, the implementation section begins - in this section all code will be written, and the file is finally closed with the End. (including the period) keyword.


2 comments:

  1. Interesting. Keep blogging, I will visit your blog regularly.
    Regards,
    Handoko.

    ReplyDelete
    Replies
    1. Thanks Handoko, I will publish as I learn and try to focus on the things that are special in Oxygene.

      Delete