zoukankan      html  css  js  c++  java
  • ansistring和unicode的序列和还原

    ansistring和unicode序列

    delphi2009以前的所有版本,默认字符串都是ansistring,字符串中的一个字符刚好就是一个字节。

    后面的DELPHI版本,默认字符串是unicode,字符串中的一个字符不再是一个字节。

    那么,可以写一个通用的ansistring和unicode序列函数,让它适配所有的delphi版本。

    FValue: TBytes;

    procedure TMsgPack.setAsString(pvValue: string);
    begin
      FDataType := mptString;
      if SizeOf(Char) = 2 then //unicode
      begin
        SetLength(FValue, length(pvValue) shl 1);
        Move(PChar(pvValue)^, FValue[0], Length(FValue));
      end else //ansistring
      begin
        SetLength(FValue, length(pvValue));
        Move(PChar(pvValue)^, FValue[0], Length(FValue));
      end;
    end;
    

      

    function TMsgPack.getAsString: String;
    var
      len:Cardinal;
    begin
        len := Length(FValue);
        if SizeOf(Char) = 2 then //unicode
        begin
          SetLength(Result, len shr 1);
          Move(FValue[0],PChar(Result)^, len);
        end else  //ansistring
        begin
          SetLength(Result, len);
          Move(FValue[0],PChar(Result)^, len);
        end;
    end;
    

      

  • 相关阅读:
    位图索引(Bitmap Index)的故事
    Oracle 用户管理
    Linux中hosts文件的修改
    oracle 错误码 ORA-00119 / ORA-00130
    Oracle 外键约束
    Oracle Basic Ready Notes
    SQL语句Tips
    AWK 简明教程
    JObject对json的操作
    C#Stopwatch的使用,性能测试
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/13716073.html
Copyright © 2011-2022 走看看