PowerBuilder可以使用啊 OLETxnObject EmpObjInteger li_rcEmpObj = CREATE OLETxnObjectli_rc = EmpObj.ConnectToNewObject("PB70COM.employee")IF li_rc < 0 THEN DESTROY EmpObj MessageBox("Connecting to COM Object Failed", & "Error: " + String(li_rc)) ReturnEND IF// Perform some work with the COM object...// If the work completed successfully, commit// the transaction and disconnect the objectEmpObj.SetComplete()EmpObj.DisconnectObject()
2、在属性窗口将类模块的名称属性改为clsDice。
3、从工程菜单中选择工程属性,将工程名称改为MyDLL。
4、从文件菜单中选择保存clsDice,将类模块保存为myDice.cls。
5、添加以下代码:
Option ExplicitPrivate Max, Point As IntegerPublic Property Get Result() As Integer
Result = Point
End PropertyPublic Property Get Maxpoint() As Integer
Maxpoint = Max
End PropertyPublic Property Let Maxpoint(num As Integer)
Max = num
End PropertyPublic Sub Throw()
Randomize
Point = Int(Rnd * Max) + 1
End SubPrivate Sub Class_Initialize()
Max = 6
End Sub
这个类模块定义了clsDice对象的两个属性和一个方法,这些属性和方法模拟了掷色子的过程。其中Maxpoint属性表示色子的面数,加入Property Let语句可让用户修改色子的面数;Result属性表示最后掷出色子的点数;Throw方法代表掷色子的动作;Private Sub Class_Initialize语句将色子的面数缺省的设置为6面。
最后,从文件菜单中选择生成mydll.dll,并保存。下面,我们来引用类clsDice:
dice.asp
' 使用CreateObject函数创建clsDice对象实例(前面创建的ActiveX.DLL--MYDLL.DLL文件)
<!--METADATA TYPE="typelib" FILE="Path/mydll.dll" -->
' Path是mydll.dll在机器上存放的路径
<html>
<head>
<title>精彩春风之调用DLL文件</title>
</head>
<body>
<%
On Error Resume Next
'"赦免"程序错误If Request.Form("T1")="" then
Session("point") = 6
Else
Session("point")=Request.Form("T1")
End If
' 用Session("point")来存放色子面数Set dice1=Server.Createobject("MyDLL.clsDice")
' 使用set语句创建dice1对象,其中MyDLL是上面创建dll文件时的工程名,clsDice为类模块的名称If Request.ServerVariables("Request_Method")="POST" then
dice1.Maxpoint = Session("point")
' 设定色子的面数
dice1.Throw
' 掷色子
%>
<form method="POST" action="dice.asp">
<p>当色子的面数为<input type="text" name="T1" size="5" value=<% = session("point") %>>时</p>
<p><input type="submit" value="掷色子" name="B1"></p>
</form>
<p>结果:<% = dice1.Result %>点 </p>
' 返回结果
<%
Else
dice1.Maxpoint = Session("point")
%>
<form method="POST" action="dice.asp">
<p>当色子的面数为<input type="text" name="T1" size="5" value=<% = session("point") %>>时</p>
<p><input type="submit" value="掷色子" name="B1"></p>
</form>
<%
End If
%>
</body>
PB必尽只是一个Sybase的客户端。
OLETxnObject EmpObjInteger li_rcEmpObj = CREATE OLETxnObjectli_rc = EmpObj.ConnectToNewObject("PB70COM.employee")IF li_rc < 0 THEN DESTROY EmpObj MessageBox("Connecting to COM Object Failed", & "Error: " + String(li_rc)) ReturnEND IF// Perform some work with the COM object...// If the work completed successfully, commit// the transaction and disconnect the objectEmpObj.SetComplete()EmpObj.DisconnectObject()