//Code:
//Memo-Inhalt speichern:
procedure SaveLinkedMemo(FS: TFilestream; W: TWriter;
Memo: TLinkedMemo);
begin
with Memo
do
begin
W.WriteString(ClassName);
W.WriteString(
Name);
W.WriteString(Lines.Text);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var FS: TFileStream;
W: TWriter;
i: Integer;
c: TComponent;
begin
try
FS := TFileStream.Create('
C:\filertest.cfg', fmCreate
or fmShareExclusive);
W := TWriter.Create(FS, 4096);
except
exit;
end;
try
FS.Position := 0;
W.WriteString('
TEST!');
W.WriteString('
TestTest');
for i:=0
to Self.ComponentCount-1
do
begin
c := Self.Components[i];
If c
is TLinkedEdit
then SaveLinkedEdit(FS, W, c
as TLinkedEdit)
else If c
is TLinkedMaskEdit
then SaveLinkedMaskEdit(FS, W, c
as TLinkedMaskEdit)
else If c
is TLinkedCheckBox
then SaveLinkedCheckBox(FS, W, c
as TLinkedCheckBox)
else If c
is TLinkedMemo
then SaveLinkedMemo(FS, W, c
as TLinkedMemo)
else If c
is TLinkedRadioButton
then SaveLinkedRadioButton(FS, W, c
as TLinkedRadioButton)
else If c
is TLinkedComboBox
then SaveLinkedComboBox(FS, W, c
as TLinkedCombobox);
end;
finally
W.Free;
FS.Free;
end;
end;
//Memo-Inhalt laden:
procedure LoadLinkedMemo(sName:
String; FS: TFileStream; R: TReader;
DestForm: TForm);
var c: TComponent;
begin
c := DestForm.FindComponent(sName);
If c <>
nil then
If c
is TLinkedMemo
then
with (c
as TLinkedMemo)
do
begin
Lines.Text := R.ReadString;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var FS: TFileStream;
R: TReader;
s:
String;
begin
try
FS := TFileStream.Create('
C:\filertest.cfg', fmOpenRead
or fmShareDenyNone);
R := TReader.Create(FS, 4096);
except
exit;
end;
try
FS.Position := 0;
If R.ReadString <> '
TEST!'
then raise Exception.Create('
Falsche Dateisignatur');
If R.ReadString <> '
TestTest'
then raise Exception.Create('
Hurrah');
While FS.Position < FS.Size
do
begin
s := Lowercase(R.ReadString);
If (s='
tlinkededit')
then LoadLinkedEdit(R.ReadString, FS, R, Self)
else If (s='
tlinkedmaskedit')
then LoadLinkedMaskEdit(R.ReadString, FS, R, Self)
else If (s='
tlinkedmemo')
then LoadLinkedMemo(R.ReadString, FS, R, Self)
else If (s='
tlinkedradiobutton')
then LoadLinkedRadioButton(R.ReadString, FS, R, Self)
else If (s='
tlinkedcheckbox')
then LoadLinkedCheckbox(R.ReadString, FS, R, Self)
else If (s='
tlinkedcombobox')
then LoadLinkedComboBox(R.ReadString, FS, R, Self);
end;
finally
R.Free;
FS.Free;
end;
end;