Using
the extension
Using nonvisual classes
In PowerScript, use the classes in a nonvisual extension just as you
would a custom class user object: Declare an instance of the object, use
the CREATE statement to create the instance, invoke the object’s
functions, and destroy the instance when you have finished with it. You
can inherit from the native classes if you want to add functions or events
to the class.
At runtime, instances of the native class are created as normal
PowerBuilder objects.
In this example, the extension module contains two nonvisual native
classes: fontcallback and fontenumerator. A PowerBuilder custom class user
object, nvo_font, inherits from the fontcallback class. These statements
create instances of both classes:
|
1 2 3 4 |
fontenumerator fe nvo_font uf fe = create fontenumerator uf = create nvo_font |
After an instance of a native class has been created, the
PowerBuilder application can call methods on the object. Each native class
must implement an Invoke method that the PowerBuilder VM calls when the
PowerBuilder application calls one of the native class’s methods. Then,
the Invoke method dispatches the method call based on the method ID or
method name. The method name is used when a native method is called
dynamically.
Using the previous example, this statement invokes the
enumprinterfonts method of the instance of the fontenumerator
class:
|
1 |
fe.enumprinterfonts(uf) |
Destroying the PBNI object
instance
When the PowerBuilder application no longer needs an instance of a
nonvisual class and a DESTROY statement is issued, by either the user or
the garbage collector, or when the window or visual control that contains
a visual class is closed, the PowerBuilder VM destroys the instance by
calling the native class’s Destroy method.