Author: Pieter Valentijn Saving and loading Component Published Propertys to disk Answer: The TStreams Class has a nice feature Couse it can stream component propertys in just one line . So here's the complete unit where i Stream the component If your class is not in the same unit you will have to register it . 1 { 2 procedure RegisterClasses(AClasses: array of TPersistentClass); 3 4 Description 5 6 Call RegisterClasses to register a set of custom classes in a single line. Each 7 class is registered by calling RegisterClass. Unregistered classes can’t be loaded 8 or saved by the VCL streaming system. 9 } 10 11 unit Unit1; 12 13 interface 14 15 uses 16 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 17 StdCtrls; 18 19 type 20 // jus a enumeration 21 TSomeints = 1..10; 22 // set of the enumeration 23 TExampleSet = set of TSomeints; 24 TExampleComponent = class(TComponent) 25 private 26 FASet: TExampleSet; 27 FAString: string; 28 FAFloat: Double; 29 FAInteger: Integer; 30 published 31 // Anyting you want streamed and is streameble by Delphi you can publish 32 // as property 33 property AString: string read FAString write FAString; 34 property ASet: TExampleSet read FASet write FASet; 35 property AInteger: Integer read FAInteger write FAInteger; 36 property AFloat: Double read FAFloat write FAFloat; 37 end; 38 39 TForm1 = class(TForm) 40 SaveToStream: TButton; 41 LoadFromStream: TButton; 42 OpenDialog1: TOpenDialog; 43 SaveDialog1: TSaveDialog; 44 EAFloat: TEdit; 45 EAstring: TEdit; 46 procedure SaveToStreamClick(Sender: TObject); 47 procedure FormCreate(Sender: TObject); 48 procedure FormDestroy(Sender: TObject); 49 procedure LoadFromStreamClick(Sender: TObject); 50 private 51 FExampleComponent: TExampleComponent; 52 procedure SetExampleComponent(const Value: TExampleComponent); 53 { Private declarations } 54 public 55 property ExampleComponent: TExampleComponent read FExampleComponent write 56 SetExampleComponent; 57 procedure ObjectToGui; 58 procedure GuiToObject; 59 { Public declarations } 60 end; 61 62 var 63 Form1: TForm1; 64 65 implementation 66 67 {$R *.DFM} 68 69 procedure TForm1.SaveToStreamClick(Sender: TObject); 70 var 71 AStream: TMemoryStream; 72 begin 73 if SaveDialog1.execute then 74 begin 75 GuiToObject; 76 AStream := TMemoryStream.Create; 77 try 78 AStream.WriteComponent(ExampleComponent); 79 AStream.SaveToFile(SaveDialog1.FileName); 80 finally 81 AStream.free; 82 end; 83 end; 84 end; 85 86 procedure TForm1.SetExampleComponent(const Value: TExampleComponent); 87 begin 88 FExampleComponent := Value; 89 end; 90 91 procedure TForm1.FormCreate(Sender: TObject); 92 begin 93 // this is the Procedure To Call if you want to Use components not defined 94 // in this unit ; 95 // RegisterClasses([TButton,TMemo,TEnz]); 96 FExampleComponent := TExampleComponent.Create(Self); 97 end; 98 99 procedure TForm1.FormDestroy(Sender: TObject); 100 begin 101 FExampleComponent.free; 102 end; 103 104 procedure TForm1.LoadFromStreamClick(Sender: TObject); 105 106 var 107 AStream: TMemoryStream; 108 begin 109 if OpenDialog1.execute then 110 begin 111 AStream := TMemoryStream.Create; 112 try 113 AStream.LoadFromFile(OpenDialog1.FileName); 114 AStream.ReadComponent(ExampleComponent); 115 ObjectToGui; 116 finally 117 AStream.free; 118 end; 119 end; 120 end; 121 122 procedure TForm1.GuiToObject; 123 begin 124 ExampleComponent.AString := EAstring.Text; 125 ExampleComponent.AFloat := StrToFloat(EAFloat.Text); 126 end; 127 128 procedure TForm1.ObjectToGui; 129 begin 130 EAstring.Text := ExampleComponent.AString; 131 EAFloat.Text := FloatToStr(ExampleComponent.AFloat); 132 end; 133 134 end. Component Download: http://www.xs4all.nl/~suusie/Pieter/Programs/StreamingComponent.ziphttp://www.xs4all.nl/~suusie/Pieter/Programs/StreamingComponent.zip