zoukankan      html  css  js  c++  java
  • delphi 字符串string转流TStream


    function StringToFile(mString : string; mFileName : TFileName) : Boolean;
    var
    vFileChar : file of Char;
    I : Integer;
    begin
    {$I-}
    AssignFile(vFileChar , mFileName);
    Rewrite(vFileChar);
    for I := 1 to Length(mString) do
    Write(vFileChar , mString[I]);
    CloseFile(vFileChar);
    {$I+}
    Result := (IOResult = 0) and (mFileName <> '');
    end;

    function FileToString(mFileName : TFileName) : string;
    var
    vFileChar : file of Char;
    vChar : Char;
    begin
    Result := '';
    {$I-}
    AssignFile(vFileChar , mFileName);
    Reset(vFileChar);
    while not Eof(vFileChar) do
    begin
    Read(vFileChar , vChar);
    Result := Result + vChar;
    end;
    CloseFile(vFileChar);
    {$I+}
    end;

    function StreamToString(mStream : TStream) : string;
    var
    I : Integer;
    begin
    Result := '';
    if not Assigned(mStream) then Exit;
    SetLength(Result , mStream.Size);
    for I := 0 to Pred(mStream.Size) do
    try
    mStream.Position := I;
    mStream.Read(Result[Succ(I)] , 1);
    except
    Result := '';
    end;
    end;

    function StringToStream(mString : string; mStream : TStream) : Boolean;
    var
    I : Integer;
    begin
    Result := True;
    try
    mStream.Size := 0;
    mStream.Position := 0;
    for I := 1 to Length(mString) do
    mStream.Write(mString[I] , 1);
    except
    Result := False;
    end;
    end;

  • 相关阅读:
    VC++读写文件
    VC++编译说明
    VC++时间函数总结
    VC++多工程项目
    VC++全局变量初始化
    Linux 系统免密码登陆远程服务器
    debian 系统安装配置apache
    数据库授权
    Mysql 主从服务器数据同步
    centos Install Docker
  • 原文地址:https://www.cnblogs.com/xtfnpgy/p/9287487.html
Copyright © 2011-2022 走看看