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: