How to write COM and COM + programs in PB.

xiaoxiao2021-03-06  72

COM / COM as a new technology for replacing OLE, has been there for a long time, and PB7 has already provided support, but from the real situation, it seems that everyone is not a lot, in fact, for the new generation of Internet applications It can still play a big role. Below I will talk about my opinion and experience from the generation, call, and application scope of COM / COM components. I will use PB10 to make an instructions for development tools. Suppose you want to do an expression Calculated COM components, I think this example is typical, used in DataStore, DataWindowObject, user object, etc., neither is too simple, not too complicated (not much code).

First of all the most basic operations, you must have a Workspace first, then open the COM / COM Create Wizard:

After selecting the project, directly next, basically do not change, it will be completed.

After the creation is complete, the system has some basic objects:

The following is established in an extended DataWindowObject, which is mainly used to calculate the expression, as long as there is a column, save its name to CALC

Then create a function of calculating expressions in the n_genapp object:

Public function string of_calc (string as_expression); Datastore LDS_CALC STRING LS_RTN

LDS_CALC = CREATE DATASTORE LDS_CALC.DataObject = "CALC" lds_calc.insertrow (0)

Ls_rtn = lds_calc.describe ("Evaluate ('" as_expression "") ") Destroy LDS_CALC RETURN LS_RTN END FUNCTION

Let's open the Project object p_genapp_commts for release.

Note that in the released Project object properties, you need to modify to publish the entire PBL object.

After the release is complete, you can call. First try the PB program call:

New program, and windows:

Place a button on the window, write the code in the button:

OleObject oleobj integer li_rc

OleObj = CREATE OLEObject li_rc = OleObj.ConnectToNewObject ( "PB100.n_genapp.1.0") IF li_rc <0 THEN DESTROY OleObj MessageBox ( "Connecting to COM Object Failed", "Error:" String (li_rc)) Return END IF sle_2. Text = string (sle_1.text)) oleobj.disconnectObject () DESTROY oleobj After execution, you can see the calculation result.

Let's take a look at how this COM component is called in other development tools, taking BCB6 as an example:

First import GenApp.dll into the type library:

Perform the installation, install the COM component to the control panel, then create a window, place several controls:

Click Click Click on the "calling the PBCOM" button:

WideString LS_EXPRESS; LS_EXPRESS = Edit1-> text; edit2-> text = CoClass_n_genapp1-> of_calc (ls_express);

Click the button to see the calculation result.

The VB call is also relatively simple, and the VC call is slightly complex, which is not embedded.

转载请注明原文地址:https://www.9cbs.com/read-95481.html

New Post(0)