Object oriented programming |
Overview |
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
or
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 |
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 |
Static components |
User defined and predefined QT parts of a component |
Further information |