Parameters for IE delivery in OCX (2002530 three gold copyright)

zhaozj2021-02-11  177

Parameters for IE delivery in OCX (2002/5/30 three gold copyright)

If your project belongs to the OCX project, and you need to connect the database server. So, the project should be appropriate

Should be different database connection parameters, such as data server name, database name, user name, password, etc.

The project should not be modified when changing. This requires OCX engineering to carry parameters. How do you do it? Look down.

Before you look at this article, it is best to look at another article written by Tricen. "EXE project and OCX

The transformation of the project ". Otherwise, the consequences are at your own risk. Don't be afraid, ONLY a Joke! :), but, three gold still persuade you to see

Let's take a few things you will understand. If your OCX project master Form is ordinary form, and inherited

ActiveForm, Then, Let's Go on the project!

In order to facilitate explanation, assume that the ActiveForm's name in the project is ActiveFormX, the unit file is

ActiveFormx.PAS, the project master Form's Name is frmmain, the unit file is Mainform.PAS. Always say

Come, that is, add an intermediate class between TactiveFormx and TFRMMain, and the connection of the parameters

Receipt. Set this type as TactiveFormNewx, because this class is the middle class of both, you need to put the parent of TfrmMain

The class is changed from TACTIVEFORMX to this class. Open Mainform.PAS to find TfrmMain's statement:

TfrmMain = Class (TactiveFormX) is changed to TfrmMain = Class (TACTIVEFORMNEWX), and

TactiveFormNewx inherits in TactiveFormx. The declaration and implementation of TactiveFormnewx is as follows, you should

Turn it to the TactiveFormX in the ActiveFormx.Pas unit.

Tactiveformnew = Class (TactiveFormX, IPERSISTPROPERTYBAG)

public

ServerName, DBName, UserName, Userpassword: String;

protected

Function ipersistpropertybag.initnew = persistpropertybaginitnew;

Function IPersistPropertybag.Load = PersistPropertybagLoad;

Function IPersistPropertybag.save = persistpropertybagsave;

Function ipersistpropertybag.getclassid = persistpropertybaggetClassID;

Function persistPropertybaginitnew: hResult; stdcall;

Function PersistPropertybagload (const ppropbag: iPropertybag; Const Perrorl:

Irrorlog): hResult; stdcall;

Function persistpropertybagsave (const ppropbag: iPropertybag; fcleardirty: bool;

FsaveAllProperties: Bool: HRESULT; stdcall;

Function PersistPropertyBaggetClassID (Out ClassID: Tclsid): hResult; stdcall;

END;

Function TactiveformNewX.PersistPropertybaginitnew: HRESULT; Begin

Result: = S_OK;

END;

Function Tactiveformnewx.PersistPropertybagLoad (const ppropbag: iPropertybag;

Const Perrorlog: IrrorLog): hResult; stdcall;

VAR

Str: olevariant;

Begin

IF Ppropbag.read ('ServerName', Str, Perrorl) = S_OK THEN

ServerName: = STR;

IF ppropbag.read ('dbname', str, perrorlog) = s_ok then

DBNAME: = STR;

IF ppropbag.read ('username', str, perrorlog) = S_OK THEN

Username: = STR;

IF Ppropbag.read ('Userpassword', Str, Perrorl) = S_OK THEN

Userpassword: = STR;

Result: = S_OK;

END;

Function TactiveFormnewx.PersistPropertyBagsave (const ppropbag: iPropertybag;

FCLEARDIRTY: BOOL; fsaveallproperties: bool): hResult;

Begin

Result: = S_OK;

END;

Function TactiveFormnewx.PersistPropertyBaggetClassId (Out ClassID: Tclsid):

HRESULT; STDCALL;

Begin

Result: = S_OK;

END;

It is not difficult to see from the code that this class has four public members: ServerName, DBNAME, Username,

Userpassword. The parameter is passed to them. Since it is a member of public members, and tfrmmain is this class

Class, so you can get these four values ​​in TFRMMain. Note that the code should be written in TFRMMain

Once onshow, not oncreate.

Writing like this in IE:

ClassID = "CLSID: 3E71BE48-9AE1-431D-BD68-B17AA355BF38"

Codebase = "ActiveFormProj1.ocx # version = 1, 0, 0"

Width = 538

HEIGHT = 350

Align = center

HSPACE = 0

vSpace = 0

>

If you want to add or reduce parameters, don't say more! OK, solve.

Have friends to express: "My OCX project master form is Tactiveform, shot your way, I

You can inherit my TACTIVEFORM inheritance in this class, I can receive the same approach in TactiveForm! "Then I tell you that the parameters can indeed get, but if you reopen your work,

Press F11 to look at it, Tactiveform said that attributes and ordinary forms have no two, although the program is not

Error, but in addition to what is nothing to do with me. You have to ask why? I am a big head, I have to rest.

More more good articles in the three gold homepage - Tian Mingxin Cang

http://vip.6to23.com/tianmingxin

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

New Post(0)