|
EXAMPLE:
$TYPECHECK ON
$Include "Rapidq.inc"
Declare Sub routine1
Declare Sub event_click
Type button extends QBUTTON
On_Click as EVENT(event_click)
EVENT OnClick
button.caption="check"
if button.On_Click<>0 then CALLFUNC button.On_Click
END EVENT
End type
CREATE Form AS QFORM
Caption="Form1"
Width=320
Height=240
Center
CREATE Button1 AS button
Caption="Button1"
Left=34
Top=41
On_Click=routine1
END CREATE
END CREATE
Form.ShowModal
sub routine1
form.Caption
= "check"
end sub
|
An object using of the API functions to call an external file little comprising the declaration of all the API functions but that would increase the size of the program compiled with the final one.
The declaration of API functions can be included in the file of the
component object, but as several object can use the same API functions
, there
are two way of proceeding in order to avoid a multiple declaration
for the same function:
a) To use the directives of compilation:
$IFNDEF API_1
$DEFINE API_1
Declare Function
GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
$ENDIF
b) To use names of function different for the same API function:
Declare Function GetDC_ObjectName Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
the example above uses the name of the object in extension of the name
of the function.
The constants necessary to the API functions can be declared same manner.
|
A new object inheriting a standard object does not need to have
its parent property redefined.
On the other hand if one adds components visible as a new field of
the object, it is necessary to carry out the assignment of the parent
properties of each one in the routine constructor or a method.
EXAMPLE:
Type a extends QPanel
bt as qbutton
img as qimage
constructor
bt.parent=a
img.parent=a
end constructor
end type
If a new object is created without heritage and using API functions
to obtain a visible component, a field parent must be defined in this one.
This field parent must be of Long type or Integer and can be
defined like property using routines PROPERTY.
This object will be able to be imbricated in a structure CREATE has
condition of carrying out the assignment of the property parent by the
handle of the parent object.
EXAMPLE:
Type a extends QObject
Parent as integer
PROPERTY SET SetParent
PROPERTY SET SetParent(parent
as integer)
a.Parent=parent
'use handle
parent for API function
END PROPERTY
end type
CREATE Form as QFORM
width=200
height=100
CREATE obj as a
parent=form.handle
END CREATE
END CREATE
Form.ShowModal
Another method of definition exists but does not allow the overlap with
CREATE, it consists has to pass the parent object in parameter at the time
of the declaration of a variable of personalized the object type.
The only problem being which one can have only of the objects of a
single type identified by the parameter of the object type.
In the example below the property parent is initialized in the routine
constructor object, so it is not necessary to affect the property parent
in the program since the Obj variable is declared with the Form variable
passed in parameter.
EXAMPLE:
Type a<QFORM> extends QObject
parent as long
constructor
parent=QFORM.handle
end constructor
end type
CREATE Form as QFORM
width=200
height=100
END CREATE
dim obj as a<Form>
Form.ShowModal
|
If the fields of an object are accessible in reading as in writing
for the user, it is possible to limit their access in reading only by defining
them in property.
In the example below, the field parent is defined in property and can
be used in reading in a program.
When the user wants used the property in writing, the field parent
is not modified since its assignment is not carried out in routine PROPERTY
and only the methods of the object can modify the state of the field parent.
One can also put routine PROPERTY as a member deprived by adding PRIVATE:
before this one in order to have an error of so tentative compilation of
writing of the field parent.
EXAMPLE:
Type a extends QObject
Parent as integer
PROPERTY SET SetParent
PRIVATE:
PROPERTY SET SetParent(parent
as integer)
END PROPERTY
end type
|
a) the inheritance of custom components is not supported.
b) Some method redefined of an inherited object require an addition
of parameter in order to avoid an error of compilation.
this is the case for the Show methods and
ShowModal of an object QFORM as the example shows it below.
EXAMPLE:
Type b extends qform
sub Showmodal(title
as string)
b.caption =title
Super.Showmodal
end sub
end type
CREATE Form AS b
Caption = "Rapid-Q
Code Viewer"
Width = 234
Height = 251
Center
OnClick=show
END CREATE
Form.ShowModal ("Check")
c) If one uses variables local of the same name in the methods of a
personalized object, the object cannot be declared in local variable of
a routine but only into total of the program.
This can be solved by having different variables local of name in the
methods of an object.
In the same way, two objects cannot have the same name of variables
local in their methods if they are declared in local variable of a routine.
The solution has this say operation will be to declare these variables
in fields private of the object and not to have any variables local in
the methods of this one.
d) The components personalized cannot have passed in parameters
of a routine.