Start pb7.0, create an invisible user object "uo_customer", create a new "object", and select "custom class"
Type and click "ok".
Write the following program in the newly created user object:
1. Declare instance variables "instance variables". For types that are not supported in com, please declare them as protected types. protected:
datastore ds_datastore
2. Create three new member functions:
int uf_connect()//Used to connect to the database and create datastore objects.
Code:
sqlca.dbms="odbc"
sqlca.database="webdw"
sqlca.autocommit=false
sqlca.dbparm="connectstring=''dsn=webdw;uid=dba;pwd=sql''"
connect using sqlca;
ds_datastore =create datastore
if sqlca.sqlcode=0 then
return 1
else
return -1
end if
void uf_disconnect()//Used to disconnect the database and release the datastore object.
if isvalid(ds_datastore) then destroy ds_datastore
disconnect using sqlca;
resultset uf_retrieve()//Read customer information
resultset lrs_customers
ds_datastore.dataobject="d_customer"
ds_datastore.retrieve()
ds_datastore.generateresultset(lrs_customers)//Generate result set
return lrs_customers//Return the result set. Finally, save the changed object as "uo_customers".
Create a COM component project, create a new "project", select "Com/mts component wizard", and confirm.
Define a name "p_recordset_com" for the project
Next, select the user object "uo_customer" to generate com
Set the interface properties after generating the COM component. You can use the default here.
Then define the program id of the component yourself as "pb70.uocustomer",
Then select the dll file name of the com component, click "new" to generate "component server appid",
Also generate "type library id". Finally, select the pb resource file name and registration method. After that, the system will give you the general information of the user settings, and then choose to generate "to do list"
This completes a project to generate COM components, named "p_test_com".
Compile the project and register the components. Open the generated project, select the corresponding pbl file and user object, and compile.
Next, we create an asp web page to call this pb com.
<head><title>pb com</title></head>
<body>
<%
set customers=server.createobject("pb70.uo_customers")
iflag=customers.uf_connect()
set rs=customers.uf_retrieve()
'www.downcodes.com
%>
<table>
<%rs.movefirst
do while not rs.eof
%>
<tr>
<td><%=rs("lname")%></td>
<td><%=rs("address")%></td>
<td><%=rs("city")%></td>
</tr>
<%rs.movenext
loop
rs.close
customers.uf_disconnect()
%>
</table>
</body>
Save it as an asp file.
Finally, you can browse the asp file in the browser.
Note: pb7.0 and pb8.0 are basically the same. Readers can practice it by themselves.