3

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 for a object.

My guess is that in PB 9, variables/properties are very similar in their usage and implementation.

contactmatt
  • 18,116
  • 40
  • 128
  • 186
  • 1
    Can you clarify what you are looking for in "properties" and, if by "public variables" you mean public-access instance variables, how they fall short. If we understand what you're after, we're more likely to be able to help. (At least *I'm* fuzzy on the concept.) – Terry Jan 19 '11 at 03:08

2 Answers2

5

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.

Community
  • 1
  • 1
Hugh Brackett
  • 2,706
  • 14
  • 21
3

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:

Powerbuilder accessor/mutator code

(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

)

Community
  • 1
  • 1
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148