unit fmDemoMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Edit1: TEdit;
    Memo1: TMemo;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ColorDialog1: TColorDialog;
    FontDialog1: TFontDialog;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    mss : TMemoryStream;

    procedure InitCustomizedComponents;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  MYCMPFILE = 'CustomizedComponents.cks';

procedure TForm1.FormCreate(Sender: TObject);
begin
  mss := TMemoryStream.Create;
  InitCustomizedComponents;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if Assigned(mss) then
  begin
    mss.SaveToFile(MYCMPFILE);
    FreeAndNil(mss);
  end;
end;

procedure TForm1.InitCustomizedComponents;
begin
  if (FileExists(MYCMPFILE)) then
  begin
    mss.LoadFromFile(MYCMPFILE);
    try
      mss.ReadComponent(Edit2);
    except
      on Exception do;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  mss.Clear;
  mss.WriteComponent(Edit2);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if (Self.ColorDialog1.Execute) then
    Edit2.Color := Self.ColorDialog1.Color;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if (Self.FontDialog1.Execute) then
    Edit2.Font := Self.FontDialog1.Font;
end;

end.
