 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Fiachra Bonner Guest
|
Posted: Wed Feb 21, 2007 2:10 am Post subject: SoapFormatter.Deserialize not working "correctly" |
|
|
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 |
|
 |
|
|
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
|
|