PowerBuilder使用心得 (2)在线教程

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 22:39:26
在PowerBuilder中使用 OLE Automation

  PB5 不仅可以支持OLE Automation Client, 而且可以很方便地做OLE Automation Server. 事实上,每个user object 都是OA Enabled的。

如果外面的应用程序要使用PB的User Object, 只需作如下调用:

1. 在VB中调用

    Dim PBObject as object

    'Create the ole object at first

    PBObject = CreateObject("uo_test") 'uo_test is my userobject in PB

    if PBObject is nothing then

     REM Error handling

    else

     PBObject.SomeAttribute = "some value"

     PBObject.DoSomething("Method parameter")

    end if

    'Disconnect the OLE object

    PBObject = nothing

2. 在PB中使用其它PB程序的对象

    OleObject PBObject

    long status

    PBObject = CREATE OleObject

    status = PBObject.ConnectToNewObject("uo_test")

    if (status<0) then

     // Error handling

    else

     PBObject.SomeAttribute = "some value"

     PBObject.DoSomething("Method parameter")

    end if

    // Destroy the object after quiting program

    DESTROY PBObject

  当然,如果要向上面如此方便地使用PB的user object, 使其在外部可被驱动,必须在系统的注册数据库中有记录。利用PB5提供的Install Builder, 可以方便地生成注册所需要的注册数据和Type Library.

Tags:

作者:佚名
分享到: 微信 更多