BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What am I doing Wrong here? I'm Not Understanding....

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ActiveX Controls Development
View previous topic :: View next topic  
Author Message
Tom Grills
Guest





PostPosted: Wed Oct 01, 2003 3:26 pm    Post subject: What am I doing Wrong here? I'm Not Understanding.... Reply with quote



I think I'm really close here and I've read that each object has to have
it's own methods to store it's state to Ipersist so I've placed the
Tfilestream read/write in the load and save methods. When I use it in an
application, I can save, clear and reload the property, but if I end the
app, restart it and try to load the state, all I see in Property1 is the
string "TPObj" rather than my saved property1 value.... What am I doing
wrong here? I'm sure it's something pretty basic, but I'm at a loss....

Any help or reference examples would be greatly appreciated...I'm pulling my
hair out not being able to find relevent examples of AutoObjects actually
implementing these functions...

Thank you,

Tom Grills

======== CODE HERE ============

TPObj = class(TAutoObject, IPObj, IPersistFile)
private
FProp1:WideString;
protected
{ Protected declarations }

function GetClassID(out classID: TCLSID): HResult; stdcall;
function IsDirty: HResult; stdcall;
function SaveCompleted(pszFileName: POleStr): HResult; stdcall;
function GetCurFile(out pszFileName: POleStr): HResult; stdcall;
function Get_Property1: WideString; safecall;
procedure Set_Property1(const Value: WideString); safecall;


public
function Load(pszFileName: POleStr; dwMode: Longint): HResult; stdcall;
function Save(pszFileName: POleStr; fRemember: BOOL): HResult; stdcall;
procedure PF1Load(pszFileName: PWideChar; dwMode: Integer); safecall;
procedure PF1Save(pszFileName: PWideChar; FRemember: WordBool);
safecall;
property property1:widestring read Get_Property1 write Set_Property1;
end;

implementation

uses ComServ;

function TPobj.GetClassID(out classID: TCLSID): HResult; stdcall;
begin
classid:=CLASS_PObj;
result:=S_OK;
end;

function TPobj.IsDirty: HResult; stdcall;
begin
result:=S_FALSE;
end;

Function TPObj.Load(pszFileName: POleStr; dwMode: Integer):HRESULT;
stdcall;
var PFile:Tfilestream;
S:integer;
begin
Pfile:=Tfilestream.create(pszFileName,dwmode);
pfile.read(s,sizeof(integer));
pfile.read(fprop1,s);
pfile.Free;
result:=S_OK;
end;

function TPobj.Save(pszFileName: POleStr; fRemember: BOOL): HResult;
stdcall;
var PFile:Tfilestream;
S:integer;
begin
Pfile:=Tfilestream.create(pszFileName,Fmcreate);
s:=length(fprop1);
pfile.Write(s,sizeof(integer));
pfile.Write(fprop1,s);
pfile.Free;
result:=S_OK;
end;

function TPobj.SaveCompleted(pszFileName: POleStr): HResult; stdcall;
begin
result:=S_OK;
end;

function TPobj.GetCurFile(out pszFileName: POleStr): HResult; stdcall;
begin
result:=S_OK;
end;

function TPObj.Get_Property1: WideString;
begin
result:=FProp1;
end;

procedure TPObj.Set_Property1(const Value: WideString);
begin
FProp1:=Value;
end;

procedure TPObj.PF1Load(pszFileName: PWideChar; dwMode: Integer);
begin
Load(pszfilename,dwmode);
end;

procedure TPObj.PF1Save(pszFileName: PWideChar; FRemember: WordBool);
var Newbool:BOOL;
begin
newbool:=Fremember;
Save(pszFilename,newbool);
end;


initialization
TAutoObjectFactory.Create(ComServer, TPObj, Class_PObj,
ciMultiInstance, tmApartment);
end.
================= END CODE =======




Back to top
Neil Moss
Guest





PostPosted: Thu Oct 02, 2003 8:40 am    Post subject: Re: What am I doing Wrong here? I'm Not Understanding.... Reply with quote



Hi Tom,

Not sure why the "TPObj" is returned, but I think your Load and Save are
flawed in that you are saving the length of FProp1 and writing that many
bytes to the stream, but FProp1 is a WideString, so the actual number of
bytes to read and write is Length(FProp1) * 2.

Cheers,
Neil Moss.

"Tom Grills" <Tgrills (AT) NODamnSpam (DOT) houston.rr.com> wrote

Quote:
I think I'm really close here and I've read that each object has to have
it's own methods to store it's state to Ipersist so I've placed the
Tfilestream read/write in the load and save methods. When I use it in an
application, I can save, clear and reload the property, but if I end the
app, restart it and try to load the state, all I see in Property1 is the
string "TPObj" rather than my saved property1 value.... What am I doing
wrong here? I'm sure it's something pretty basic, but I'm at a loss....

Any help or reference examples would be greatly appreciated...I'm pulling
my
hair out not being able to find relevent examples of AutoObjects actually
implementing these functions...

Thank you,

Tom Grills

======== CODE HERE ============

TPObj = class(TAutoObject, IPObj, IPersistFile)
private
FProp1:WideString;
protected
{ Protected declarations }

function GetClassID(out classID: TCLSID): HResult; stdcall;
function IsDirty: HResult; stdcall;
function SaveCompleted(pszFileName: POleStr): HResult;
stdcall;
function GetCurFile(out pszFileName: POleStr): HResult;
stdcall;
function Get_Property1: WideString; safecall;
procedure Set_Property1(const Value: WideString); safecall;


public
function Load(pszFileName: POleStr; dwMode: Longint): HResult;
stdcall;
function Save(pszFileName: POleStr; fRemember: BOOL): HResult;
stdcall;
procedure PF1Load(pszFileName: PWideChar; dwMode: Integer); safecall;
procedure PF1Save(pszFileName: PWideChar; FRemember: WordBool);
safecall;
property property1:widestring read Get_Property1 write Set_Property1;
end;

implementation

uses ComServ;

function TPobj.GetClassID(out classID: TCLSID): HResult; stdcall;
begin
classid:=CLASS_PObj;
result:=S_OK;
end;

function TPobj.IsDirty: HResult; stdcall;
begin
result:=S_FALSE;
end;

Function TPObj.Load(pszFileName: POleStr; dwMode: Integer):HRESULT;
stdcall;
var PFile:Tfilestream;
S:integer;
begin
Pfile:=Tfilestream.create(pszFileName,dwmode);
pfile.read(s,sizeof(integer));
pfile.read(fprop1,s);
pfile.Free;
result:=S_OK;
end;

function TPobj.Save(pszFileName: POleStr; fRemember: BOOL): HResult;
stdcall;
var PFile:Tfilestream;
S:integer;
begin
Pfile:=Tfilestream.create(pszFileName,Fmcreate);
s:=length(fprop1);
pfile.Write(s,sizeof(integer));
pfile.Write(fprop1,s);
pfile.Free;
result:=S_OK;
end;

function TPobj.SaveCompleted(pszFileName: POleStr): HResult; stdcall;
begin
result:=S_OK;
end;

function TPobj.GetCurFile(out pszFileName: POleStr): HResult; stdcall;
begin
result:=S_OK;
end;

function TPObj.Get_Property1: WideString;
begin
result:=FProp1;
end;

procedure TPObj.Set_Property1(const Value: WideString);
begin
FProp1:=Value;
end;

procedure TPObj.PF1Load(pszFileName: PWideChar; dwMode: Integer);
begin
Load(pszfilename,dwmode);
end;

procedure TPObj.PF1Save(pszFileName: PWideChar; FRemember: WordBool);
var Newbool:BOOL;
begin
newbool:=Fremember;
Save(pszFilename,newbool);
end;


initialization
TAutoObjectFactory.Create(ComServer, TPObj, Class_PObj,
ciMultiInstance, tmApartment);
end.
================= END CODE =======







Back to top
Neil Moss
Guest





PostPosted: Thu Oct 02, 2003 9:21 am    Post subject: Re: What am I doing Wrong here? I'm Not Understanding.... Reply with quote



Tom,

I forgot to add that when reading in the WideString, you will probably need
to call SetLength(FProp1, S) before reading the bytes from the stream in
order to allocate the storage space for the bytes.

Neil Moss.


Back to top
Tom Grills
Guest





PostPosted: Thu Oct 02, 2003 11:07 am    Post subject: Re: What am I doing Wrong here? I'm Not Understanding.... Reply with quote

Neil -

Thanks for your response, but still no joy... Are there any documents
that explain this? or any code examples on how to create the autoobjects
with Ipersistfile implementation?

Tom Grills

"Neil Moss" <neil.moss (AT) sp (DOT) am.unitech.net> wrote

Quote:
Tom,

I forgot to add that when reading in the WideString, you will probably
need
to call SetLength(FProp1, S) before reading the bytes from the stream in
order to allocate the storage space for the bytes.

Neil Moss.





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ActiveX Controls Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.