如何用TFileStream实现文件内16进制数查找?请大侠们给个代码,感激不尽。

解决方案 »

  1.   

    用内存映射文件不可以吗?要是用流得现写呀,当然最主要的吗var
       // s : TMemoryStream;
        p : Pointer;
        hFile, hMapping : Hwnd;
        PP : Pointer;
        h : HWND;
        i : integer;
    begin
        //s := TMemoryStream.Create;
        if OpenDialog1.Execute then
        begin
            hMapping := 0;
            p := nil;
            hFile :=  CreateFile(PChar(OpenDialog1.FileName),GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
            if hFile <> INVALID_HANDLE_VALUE then begin
            hMapping := CreateFileMapping(hFile,nil,PAGE_READONLY,0,0,nil);
            CloseHandle(hFile);
            if hMapping <> NULL then begin
              p := MapViewOfFile(hMapping,FILE_MAP_READ,0,0,0);             //   pMapping
            end;
            for i := 0 to 9 do
            begin
                ShowMessage(Format('%.8x',[LongWord(p^)]));
                Inc(LongWord(P),4);
            end;
            UnmapViewOfFile(p);
        end;end;
      

  2.   

    写到是很简单的,但是楼主你给的分是在有点少 :)var
        s : TFileStream;
        b : array[0..3] of byte;
        i : integer;
    begin
        if OpenDialog1.Execute then
        begin
            s := TFileStream.Create(OpenDialog1.FileName,fmOpenReadWrite);
            s.Position := 0;
            for i := 0 to 9 do
            begin
                s.ReadBuffer(b,4);
                ShowMessage(Format('%.8x',[LongWord(b)]));
                s.Position := s.Position + 4;
            end;
            s.Free;
        end;
    end;