borland新闻组的一段code
Hmmm. I followed an example from one of these newsgroups and got it working
without a hitch. Did you declare support for IPersistPropertyBag in the
class definition?
Here is what mine looks like, with non-essentials removed:
class TMyActiveForm = class(TActiveForm, IMyActiveForm,
IPersistPropertyBag)
protected:
// IPersistPropertyBag
function IPersistPropertyBag.GetClassID = PersistPropertyBagGetClassID;
function IPersistPropertyBag.InitNew = PersistPropertyBagInitNew;
function IPersistPropertyBag.Load = PersistPropertyBagLoad;
function IPersistPropertyBag.Save = PersistPropertyBagSave;
function PersistPropertyBagInitNew: HResult
stdcall;
function PersistPropertyBagGetClassID(out classID: TCLSID): HResult;stdcall;
function PersistPropertyBagLoad(const pPropBag: IPropertyBag
const pErrorLog: IErrorLog): HResult
stdcall;
function PersistPropertyBagSave(const pPropBag: IPropertyBag;
fClearDirty: BOOL
fSaveAllProperties: BOOL): HResult
stdcall;
end;
implementation
(*
* IPersistPropertyBag
*)
function TMyActiveForm.PersistPropertyBagLoad(const pPropBag: IPropertyBag;
const pErrorLog: IErrorLog): HResult;
var
v : OleVariant;
begin
if pPropBag.Read('ShowLegend', v, pErrorLog) = S_OK then
Set_ShowLegend( v );
if pPropBag.Read('XMLDSOID', v, pErrorLog) = S_OK then
Set_XMLDSOID( v );
result := S_OK;
end;
function TMyActiveForm..PersistPropertyBagSave(const pPropBag: IProper
tyBag;
fClearDirty, fSaveAllProperties: BOOL): HResult;
var
v : OleVariant;
begin
v := FShowLegend;
pPropBag.Write( 'ShowLegend', v );
v := FXMLDSOID;
pPropBag.Write( 'XMLDSOID', v );
result := S_OK;
end;
function TMyActiveForm..PersistPropertyBagGetClassID( out classID: TCLSID):HResult;
begin
try
classID := Class_MyActiveForm;
Result := S_OK;
except
end;
end;
function TMyActiveForm.PersistPropertyBagInitNew: HResult;
begin
try
result := S_OK;
except
end;
end;