soo... hab jetzt das text-
dfm:
Code:
object TPanel
Left = 16
Top = 68
Width = 207
Height = 186
TabOrder = 0
end
das ist das, was geschrieben werden sollte. ich paste jetzt einfach noch mal meinen code:
Delphi-Quellcode:
procedure TFormElementSupplier.Load(FileName: string; Parent: TWinControl; Add: Boolean);
var Manager: TBaseFormElementManager;
ManagerClass: TBaseFormElementManagerClass;
ms,msc: TMemoryStream;
size: Integer;
Index: Integer;
begin
IsUnSerializing := True;
if not Add then
Elements.Clear;
ms := TMemoryStream.Create;
msc := TMemoryStream.Create;
try
ms.LoadFromFile(FileName);
ms.Position := 0;
while ms.Position < ms.Size do
begin
//read class and size of element
ms.Read(ManagerClass,sizeof(ManagerClass));
ms.Read(size,SizeOf(size));
//copy element into temporary stream to isolate it
msc.Clear;
msc.CopyFrom(ms,size);
//create manager
Manager := ManagerClass.Create;
//create element
Manager.FControl := ManagerClass.ElementClass.Create(Manager);
//unserialize element
msc.ReadComponent(Manager.FControl); //<--- knallt hier... "Stream-Lesefehler"
Manager.InitElement(Parent);
end;
finally
ms.Free;
msc.Free;
end;
IsUnSerializing := False;
end;
procedure TFormElementSupplier.Save(FileName: string);
var i,size: Integer;
ms,msc,textstream: TMemoryStream;
ManagerClass: TClass;
s: string;
begin
ms := TMemoryStream.Create;
msc := TMemoryStream.Create;
textstream := TMemoryStream.Create;
try
for i := 0 to Elements.Count -1 do
begin
//write the control
msc.Clear;
msc.WriteComponent(Elements[i].FControl);
msc.Position := 0;
size := msc.Size;
ObjectBinaryToText(msc,textstream);
msc.Position := 0;
//write the manager's class
ManagerClass := Elements[i].ClassType;
ms.Write(ManagerClass, SizeOf(ManagerClass));
//write the size of the control
ms.Write(size,SizeOf(size));
//write the control
ms.CopyFrom(msc, msc.Size);
end;
ms.Position := 0;
ms.SaveToFile(FileName);
textstream.SaveToFile(Filename + 'txt');
finally
ms.Free;
msc.Free;
textstream.Free;
end;
end;
Nicht, weil ich zu faul bin zum debuggen, sondern weil ich einfach schon alles versucht habe. "knallt hier" ist markiert in der load-procedure...
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1