Object oriented programming



Components are a very powerful feature. Basically a component allows an application to provide it's features as an embedded frame into other applications. Each component may be set up, documented and improved separately. Components increase code reuse and should be easy to use in HBasic applications.

Since object oriented programming has become a major feature of many programming languages we will implement some of the concepts in HBasic. Depending on your definition of object oriented programming you may not call the current version really object oriented but I think the base concepts already exist in class sources and components. This document should give you a short introduction what you currently can do with HBasic. 

Precompiled packages and HBasic class sources

HBasic supports two different styles of using objects. You may either create a class definition with HBasic source code (called class module or class source) or load a list of precompiled components (called package) as a shared library. A package has normally been set up with C or C++ source code and may work as a precompiled library of new HBasic functions, add an interface to an existing C library or add graphical features like QT widgets.

Some precompiled components will already be delivered with HBasic. Maybe you want to download some additional packages from the internet later. One or more components delivered in one file will be called "package ". HBasic uses a default package to describe the gui components like Buttons, Edit fields or other parts you may put into a form window. Some other packages for handling Files, Date values, standard dialogs, accessing database tables or displaying graphics may be included at runtime with a package if you need them. (See package list)

HBasic can dynamically load packages at runtime and get informations about the package from meta-data that must be distibuted with the package. (See How to create a package)

Class modules

Class modules on the other side will be defined by HBasic source code and used within other basic sources. You declare which methods, properties and events an instance of the class may handle with some HBasic statements. Have a look at the program examples to see how you can use this features.

Create components or class instances

You may create an instance of a component or a source module by using its name as a type within a variable declaration.

Dim c As comp_name


Dim c As class_name

where comp_name is the name of a component like PushButton or source module. Furthermore you may create a component by using the form-designer of HBasic. The select window on the left side of the HBasic mainwindow shows small icons for all components that you currently may use. Start the package manager and you can import more packages (and components) in your project.

If you select for example the button icon and click on the formdesigner window you will create a button widget like the one shown in the following picture.

Image 01: Icon selection and button component created in form-designer

Since components created by the form-designer will be set up before starting a basic program execution they have to be treated in another way by the HBasic compiler than components created at runtime with a Dim statement. Therefore we call this special form of components "gui-components " to separate them from components created within a Dim statement which we call "Dim components".

HBasic packages

Each HBasic package is a dynamic library that declares properties, methods/functions and events. HBasic can use this components if they have been set up with a predefined interface (See "Creating precompiled components). HBasic needs some Meta information about each methods, property or event and also stores some additional description about each component and the whole package. This information and if a package will be loaded when starting HBasic may be set up in the package manager.

If you get new packages later (download from internet or read from CD ...) you may use the in your project after loading them with the package manager. These components may add new widgets or component definitions for different functions. Everything that may be set up with C++ code may be included into HBasic as a component by setting up the additional code for the interface that HBasic needs to use the code. This is a very powerful way to use code that has been set up and published by other developers.

Visible and unvisible widgets

A component created with the formdesigner may have a visible representation like a QButton widget or might be unvisible at edittime like a library that only exports some methods. If the component has no visible widget a small square button with the icon of the component will be created on the form.

Static components

A method of a component which may be called without a component reference will be called a static method. An example of such a method is CurrentDate and CurrentTime from the HBasic Datetime package. When you call this methods they return an instance of a component which represents the current date or the current time. Since you normally want to assign this to a new component it doesn't make sense to call this method for a component which represents anothe date or time. Therefore this methods must be called without a component.

The syntax to call a static method is <component type name>.<method name> where component type name is not the name of a single component instance but the name of the component type in the package. A call to the currentdate method would therefore look like Date.CurrentDate .

User defined and predefined QT parts of a component 

Components may export methods, properties and events. You normally have already used components when you set up the GUI structure of your HBasic program.

Beside the methods, properties and events HBasic may also use predefined structures of the QT widgets that have been used to set up a component. If for example the button component is derived from the QT PushButton widget (which it normally is) you may also use some of the methods, properties and events of the QT widget without having them defined in the component source code. HBasic reads the needed description for this functionality from the metacode of the QT widgets. The following examples show how to use these structures.

Further information