在你看这篇文章之前,最好先看一下三金所写的另外一篇文章 “EXE工程和OCX
工程的转化“。否则,后果自负。别怕,only a joke!:),不过,三金还是劝你看
一下,本篇你就会明白得快一些。如果你的OCX工程主Form是普通Form,并且继承于
工程中的ActiveForm,then,let's go on!
TActiveFormNewX = 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 pErrorLog:
IErrorLog):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:IErrorLog):HResult;stdCall;
var
Str:OleVariant;
begin
if pPropBag.Read('ServerName', Str ,pErrorLog) = 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 ,pErrorLog) = 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;