cancel
Showing results for 
Search instead for 
Did you mean: 

Polymorphism/Overloading in PB

larrypeters
Explorer
0 Kudos

In a PB12.5 pfc-enabled application I have an object function with code as follows:

    public function integer of_connect(ref transaction mytr)

    mytr = create n_tr

    mytr.dbms = profilestring('my.ini', 'Switches', 'DBMS', 'ODBC')

    mytr.dbparm = profilestring('my.ini', 'Switches', 'Dbparm', '')

    connect using mytr;

    return mytr.sqlcode

   

This function is called from many places.

Sometimes case 1:

    integer            li_ret

    transaction        ltr

   

    li_ret = of_connect(ltr)

Sometimes case 2:

    integer            li_ret

    n_tr                ltr

   

    li_ret = of_connect(ltr)

Both seem to work.

Is this usage legal?

Or should I change all case 1 calls to declare ltr as 'n_tr' instead of 'transaction'

and of_connect() argument as 'n_tr'? The trouble is it is a large app and there are

maybe a thousand instances of case 1.

Could someone point me at documentation which discusses this issue or educate me in

the pros and cons of this usage?

View Entire Topic
Former Member
0 Kudos

Hi Larry,

It's totally legal, since n_tr inherits from transaction.

In both case, a n_tr object is instantiated.

The only difference is that in case 1 you won't be able to call specific functions of n_tr, if you need it then you just have to change the declaration.

Regards

Guillaume

larrypeters
Explorer
0 Kudos

Thanks Guillaume,