⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xstreams.pas

📁 《Delphi深度历险》附书源码 Delphi学习书本
💻 PAS
字号:
unit xStreams;

interface

uses Windows, SysUtils, Classes, Forms, TypInfo;

procedure SavePropertyToStream(Stream: TStream; Instance: TPersistent; PropName: string);
procedure LoadPropertyFromStream(Stream: TStream; Instance: TPersistent);

procedure ReadFormAsText(AExeName, AClassName: string; Strings: TStrings);
procedure WriteFormAsBinary(AExeName, AClassName: string; Strings: TStrings);

function VisualizeForm(Strings: TStrings): TForm;
procedure TextizeForm(AForm: TForm; Strings: TStrings);

implementation

type
  TMyWriter = class(TWriter)
  public
    procedure WriteProperty(Instance: TPersistent; PropInfo: Pointer);
  end;

  TMyReader = class(TReader)
  public
    procedure ReadProperty(Instance: TPersistent);
  end;

  { TMyWriter }

procedure TMyWriter.WriteProperty(Instance: TPersistent; PropInfo: Pointer);
begin
  inherited WriteProperty(Instance, PropInfo);
end;

  { TMyReader }

procedure TMyReader.ReadProperty(Instance: TPersistent);
begin
  inherited ReadProperty(Instance);
end;

procedure SavePropertyToStream(Stream: TStream; Instance: TPersistent; PropName: string);
begin
  with TMyWriter.Create(Stream, 4096) do
    try
      WriteListBegin;
      WriteProperty(Instance, GetPropInfo(Instance.ClassInfo, PropName));
      WriteListEnd;
    finally
      Free;
    end;
end;

procedure LoadPropertyFromStream(Stream: TStream; Instance: TPersistent);
begin
  with TMyReader.Create(Stream, 4096) do
    try
      ReadListBegin;
      while not EndOfList do ReadProperty(Instance);
      ReadListEnd;
    finally
      Free;
    end;
end;

// 盢 form 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -