How to access window variable in different .pbl with non-visual object in Powerbuilder

1.1k views Asked by At

I have window w_1 in P1.pbl

I have non-visual object n1 in p2.pbl.

In w_1 having il_ref. I would like to access the value to n_1 object.

1

There are 1 answers

10
Matt Balent On

There are a variety of ways to accomplish your task.

You can define an instance variable of type n1 on window w_1.

n1 i_n1

You would then instantiate the variable via a create statement

i_n1 = CREATE n1 

(unless the object is auto-instantiating)

Methods and variables within i_n1 are now assessable to the window (and vice versa) as long as their scope is designated PUBLIC.

Example of referencing variable on non visual from window method:

IF IsValid(i_n1) THEN
  IF i_n1.il_ref > 0... //do whatever
END IF

If your non visual is already created as a global, don't make a copy on the window, just change the code above to reference the global.

In general, to have access to classes within a .PBL file, that file must be in the library list of the application. In more current versions of PowerBuilder this is maintained in the target (.PBT). There are methods to programmatically change the library list but I won't go into these here.