Delphi 서열화 및 반서열화

Delphi       。

 :

[delphi] view plaincopyprint?function TStream.ReadComponentRes(Instance: TComponent): TComponent;  

function TStream.ReadComponentRes(Instance: TComponent): TComponent; :[delphi] view plaincopyprint?procedure TStream.WriteComponentRes(const ResName: string; Instance: TComponent);  

procedure TStream.WriteComponentRes(const ResName: string; Instance: TComponent);            ,               。           INI         (       )。

       ,               ,        。  。

    :


[delphi] view plaincopyprint?{ 
    (serialization):                        。 
            ,        。         ,            。 
       
  1、                ; 
  2、                。 
  3、         
 Delphi      TPersistent            。 
 TPersistent     
procedure DefineProperties(Filer: TFiler); virtual; 
}  
unit Unit1;  
  
interface  
  
uses  
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  Dialogs, StdCtrls;  
  
type  
  TForm1 = class(TForm)  
    Btn1: TButton;  
    Btn2: TButton;  
    Edit1: TEdit;  
    LB1: TLabel;  
    mmo1: TMemo;  
    procedure Btn2Click(Sender: TObject);  
    procedure FormCreate(Sender: TObject);  
    procedure Btn1Click(Sender: TObject);  
  private  
    SYS_PATH: string;  
  public  
  
  end;  
  
var  
  Form1: TForm1;  
  
implementation  
  
{$R *.dfm}  
  
procedure TForm1.Btn1Click(Sender: TObject);  
var  
  ts: TStream;  
  i: integer;  
begin //       
  ts := TFileStream.Create(SYS_PATH + 'serialization.txt',fmOpenRead);  
  for i := 0 to Self.ComponentCount - 1 do  
    ts.ReadComponentRes(Self.Components[i]);  
  ts.Free();  
end;  
  
procedure TForm1.Btn2Click(Sender: TObject);  
var  
  fs: TFileStream;  
  i: Integer;  
begin //      
  fs := TFileStream.Create(SYS_PATH + 'serialization.txt', fmCreate);  
  for i := 0 to Self.ComponentCount - 1 do  
    fs.WriteComponentRes(Self.Components[i].ClassName, Self.Components[i]);  
  fs.free();  
end;  
  
procedure TForm1.FormCreate(Sender: TObject);  
begin  
  SYS_PATH := ExtractFileDir(Application.ExeName) + '\';  
end;  
  
end.  

좋은 웹페이지 즐겨찾기