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 

SoapFormatter.Deserialize not working "correctly"

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML
View previous topic :: View next topic  
Author Message
Fiachra Bonner
Guest





PostPosted: Wed Feb 21, 2007 2:10 am    Post subject: SoapFormatter.Deserialize not working "correctly" Reply with quote



I have a class - TTest - with SaveToXML and LoadFromXML routines that call
SoapFormatter.Serialize & SoapFormatter.Deserialize. The SaveToXML works as
expected, however, I am getting strange results with LoadFromXML - within
the routine itself, I can examine the value of Self.FName after the call to
Deserialize and it contains a valid value, after the call FName is blanked!

I'm fairly stumped with this one, so any help would be appreciated. Is it
that Deserialize creates a new object?

Thanks,

Fiachra



program TestSOAP;

{$APPTYPE CONSOLE}

{%DelphiDotNetAssemblyCompiler
'$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.Runtime.Serialization.Formatters.Soap.dll'}

uses
System.IO,
System.Runtime.Serialization.Formatters.Soap;

type
[Serializable]
TTest = class(System.Object)
private
FName: string;

public
procedure LoadFromXML(const Filename: string);
procedure SaveToXML(const Filename: string);

property Name: string read FName write FName;
end;

procedure TTest.LoadFromXML(const Filename: string);
var
fs: FileStream;
Soap: SoapFormatter;

begin
fs := System.IO.File.OpenRead(Filename);
try
Soap := SoapFormatter.Create;
Self := TTest(Soap.Deserialize(fs));
finally
fs.Close;
end;
end;

procedure TTest.SaveToXML(const Filename: string);
var
fs: FileStream;
Soap: SoapFormatter;

begin
fs := FileStream.Create(Filename, FileMode.Create);
try
Soap := SoapFormatter.Create;
Soap.Serialize(fs, Self);
finally
fs.Close;
end;
end;

var
t: TTest;

begin
t := TTest.Create;

t.Name := 'Test1';
t.SaveToXML('c:\abc.xml'); // This works, i.e., creates c:\abc.xml with
"Test1" as the value for Name.

t.Name := '';
t.LoadFromXML('c:\abc.xml');
// Within LoadFromXML I can evalute Self.FName and see "Test1" in it; when
the call ends Self.FName is blanked out!

Console.WriteLine(t.Name);
Console.ReadLine;
end.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML 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.