zoukankan      html  css  js  c++  java
  • TComponent与String的转换(得到控件的DFM格式的描述)

    现看下面这两个方法,把一个TComponent做成String,再就是把String转成TComponent

    function ComponentToStringProc(Component: TComponent): string;
    var
      BinStream:TMemoryStream;
      StrStream: TStringStream;
      s: string;
    begin
      BinStream := TMemoryStream.Create; // 创建内存流
      try
        StrStream := TStringStream.Create(s);
        try
          BinStream.WriteComponent(Component); // 把控件描述写入内存
          BinStream.Seek(0, soFromBeginning);  // 重定位内存流
          ObjectBinaryToText(BinStream, StrStream); // 把内存流的内容写到字符流
          StrStream.Seek(0, soFromBeginning);  // 重定位字符流
          Result:= StrStream.DataString;       // 取得字符流的所有结果
        finally
          StrStream.Free;
        end;
      finally
        BinStream.Free
      end;
    end;
    
    function StringToComponentProc(Value: string): TComponent;
    var
      StrStream:TStringStream;
      BinStream: TMemoryStream;
    begin
      StrStream := TStringStream.Create(Value); // 字符流读取String
      try
        BinStream := TMemoryStream.Create;
        try
          ObjectTextToBinary(StrStream, BinStream); // 根据文字生成控件
          BinStream.Seek(0, soFromBeginning);       // 重定位内存流
          Result:= BinStream.ReadComponent(nil);    // 读取内存,返回作为一个控件使用
        finally
          BinStream.Free;
        end;
      finally
        StrStream.Free;
      end;
    end;

    http://blog.sina.com.cn/s/blog_44fa172f0101is8p.html

  • 相关阅读:
    Docker入门,看这一篇就够了
    SpringBoot15:整合JPA
    docker 常用命令备忘录
    LeetCode 93. 复原IP地址 | Python
    LeetCode 99. 恢复二叉搜索树 | Python
    LeetCode 100. 相同的树 | Python
    LeetCode 336. 回文对 | Python
    LeetCode 337. 打家劫舍 III | Python
    LeetCode 207. 课程表 | Python
    LeetCode 415. 字符串相加 | Python
  • 原文地址:https://www.cnblogs.com/findumars/p/4998891.html
Copyright © 2011-2022 走看看