RSS订阅 | 匿名投稿
您的位置:网站首页 > 单元 > 正文

delphi 读写附加数据

作者:admin 来源: 日期:2011/8/18 12:51:30 人气: 标签:

 unit uEof;

interface

uses
  Windows;

function ReadFile(FileName: String): AnsiString;
function ReadEof(Delimit1, Delimit2 :String) :String;
function WriteEof(FileName, Res, Delimit1, Delimit2 :String) :String;

implementation

function ReadFile(FileName: String): AnsiString;
var
  F             :File;
  Buffer        :AnsiString;
  Size          :Integer;
  ReadBytes     :Integer;
  DefaultFileMode:Byte;
begin
  Result := '';
  DefaultFileMode := FileMode;
  FileMode := 0;
  AssignFile(F, FileName);
  Reset(F, 1);

  if (IOResult = 0) then
  begin
    Size := FileSize(F);
    while (Size > 1024) do
    begin
      SetLength(Buffer, 1024);
      BlockRead(F, Buffer[1], 1024, ReadBytes);
      Result := Result + Buffer;
      Dec(Size, ReadBytes);
    end;
    SetLength(Buffer, Size);
    BlockRead(F, Buffer[1], Size);
    Result := Result + Buffer;
    CloseFile(F);
  end;

  FileMode := DefaultFileMode;
end;

function ReadEof(Delimit1, Delimit2 :String) :String;
var
  Buffer      :AnsiString;
  ResLength   :Integer;
  i           :Integer;
  PosDelimit  :Integer;
begin
  Buffer := ReadFile(ParamStr(0));
  if Pos(Delimit1, Buffer) > Pos(Delimit2, Buffer) then
    PosDelimit := Length(Buffer)-(Pos(Delimit1, Buffer)+Length(Delimit1))
  else PosDelimit := Length(Buffer)-(Pos(Delimit2, Buffer)+Length(Delimit2));
  Buffer := Copy(Buffer, (Length(Buffer)-PosDelimit), Length(Buffer));
  ResLength := Pos(Delimit2, Buffer)-(Pos(Delimit1, Buffer)+Length(Delimit1));
  for i := 0 to (Reslength-1) do
    Result := Result+Buffer[Pos(Delimit1, Buffer)+(Length(Delimit1)+i)];
end;

function WriteEof(FileName, Res, Delimit1, Delimit2 :String) :String;
var
  F: TextFile;
begin
  AssignFile(F,FileName);
  Append(F);
  Writeln(F,Delimit1+Res+Delimit2);
  CloseFile(F);
end;

end.


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:delphi uHTTP_Flood