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;
|
请发表评论