Powerbuilder - How to create Class Properties
How do I create/define properties for a powerbuilder class? I'm running PowerBuilder 9 and I've been using public variables like properties , but I want to know how to create/define PowerBuilder properties fo开发者_开发技巧r a object.
My guess is that in PB 9, variables/properties are very similar in their usage and implementation.
You can create properties with the undocumented indirect
keyword.
Here's an article that explains how to use the indirect keyword in PowerBuilder
The normal caution about using undocumented features applies.
Do you mean properties in the way that e.g. C# or PHP defines them, as wrappers for accessor/mutator methods - something like this (in C#)?
class TimePeriod
{
private double seconds;
public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }
}
}
EDIT: As pointed out by Hugh Brackett, this can be done by using the undocumented INDIRECT
keyword.
The classic (documented) way to do this is to write seperate accessor and mutator methods. For the example above, you would write some Powerbuilder code like this:
(or as source:
global type uo_timeperiod from nonvisualobject
end type
global uo_timeperiod uo_timeperiod
type variables
private double id_seconds
end variables
forward prototypes
public function double of_get_hours ()
public subroutine of_set_hours (double ad_seconds)
end prototypes
public function double of_get_hours ();
return id_seconds / 3600
end function
public subroutine of_set_hours (double ad_seconds);
id_seconds = ad_seconds * 3600
end subroutine
)
精彩评论