unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
cmd1: TButton;
cmd2: TButton;
procedure cmd2Click(Sender: TObject);
procedure cmd1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TMensch =
class(TObject)
public
Alter: Byte;
Name:
String;
end;
var
Form1: TForm1;
implementation
procedure TForm1.cmd1Click(Sender: TObject);
var
Mensch: TMensch;
Ser: XmlSerializer;
Writer: StreamWriter;
begin
Mensch := TMensch.Create;
Mensch.Alter := 15;
Mensch.
Name := '
fido';
Writer := StreamWriter.Create('
Mensch.xml');
Ser := XmlSerializer.Create(typeof(TMensch));
Ser.Serialize(Writer, Mensch);
Writer.Close;
end;
procedure TForm1.cmd2Click(Sender: TObject);
var
Mensch: TMensch;
Ser: XmlSerializer;
Reader: StreamReader;
begin
Reader := StreamReader.Create('
Mensch.xml');
Ser := XmlSerializer.Create(typeof(TMensch));
Mensch := Ser.Deserialize(Reader)
as TMensch;
Reader.Close;
showmessage(Mensch.
Name + '
ist ' + IntToStr(Mensch.Alter + '
Jahre alt.'));
end;
end.