08-23-2008, 12:30 PM
The Classes topic in QM help is for those that already know what is a class. Most programming languages have classes.
To understand user-defined classes, you have to be familiar with variables, user-defined types and user-defined functions. A class is an user-defined type that also has functions.
Let's create a simple rectangle class. Class definition includes class name and member variables.
Macro
Put it in some macro and compile or run the macro. It lets QM know about the new class. To make it always available, put it in a function that runs at startup. For example, in init2 (create it if does not exist).
Now create 3 member functions. To add member functions use menu File -> New -> New Member Function. The item name consists of class name, . and function name.
Member function CRect.Init
Member function CRect.Area
Member function CRect.Hypotenuse
Now the class is created and you can use it anywhere. Declare variables of CRect type and call functions using syntax variable.Function(arguments).
Macro
To understand user-defined classes, you have to be familiar with variables, user-defined types and user-defined functions. A class is an user-defined type that also has functions.
Let's create a simple rectangle class. Class definition includes class name and member variables.
Macro
Put it in some macro and compile or run the macro. It lets QM know about the new class. To make it always available, put it in a function that runs at startup. For example, in init2 (create it if does not exist).
Now create 3 member functions. To add member functions use menu File -> New -> New Member Function. The item name consists of class name, . and function name.
Member function CRect.Init
function double'width double'height
;Initializes the variable.
m_width=width
m_height=height
Member function CRect.Area
Member function CRect.Hypotenuse
function'double
;Calculates rectangle hypothenuse.
;It is distance between two opposite corners.
ret _hypot(m_width m_height)
Now the class is created and you can use it anywhere. Declare variables of CRect type and call functions using syntax variable.Function(arguments).
Macro