Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7901603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:15:53+00:00 2026-06-03T09:15:53+00:00

in this article delphi.net(prism) support async file io. Delphi(Native/VCL) has Async File IO Class

  • 0

in this article delphi.net(prism) support async file io.
Delphi(Native/VCL) has Async File IO Class too?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:15:54+00:00Added an answer on June 3, 2026 at 9:15 am

    Have you seen this code? http://pastebin.com/A2EERtyW

    It is a good start for ansynchronous file I/O, but personally I would write a wrapper around the standard TStream class to maintain compatibility with VCL/RTL.

    EDIT 2: This one looks good, too. http://www.torry.net/vcl/filedrv/other/dstreams.zip

    I am posting it here just in case it disappears from Pastebin:

    unit xfile;
    
    {$I cubix.inc}
    
    interface
    
    uses
      Windows,
      Messages,
      WinSock,
      SysUtils,
      Classes;
    
    const
      MAX_BUFFER = 1024 * 32;
    
    type
      TFileReadEvent = procedure(Sender: TObject; const Buffer; Count: Integer) of object;
    
      TAsyncFile = class
      private
        FHandle: THandle;
        FPosition: Cardinal;
        FReadPending: Boolean;
        FOverlapped: TOverlapped;
        FBuffer: Pointer;
        FBufferSize: Integer;
        FOnRead: TFileReadEvent;
        FEof: Boolean;
        FSize: Integer;
        function ProcessIo: Boolean;
        procedure DoOnRead(Count: Integer);
        function GetOpen: Boolean;
      public
        constructor Create(Filename: string; BufferSize: Integer = MAX_BUFFER);
        destructor Destroy; override;
        procedure BeginRead;
        procedure Seek(Position: Integer);
        procedure Close;
        property OnRead: TFileReadEvent read FOnRead write FOnRead;
        property Eof: Boolean read FEof;
        property IsOpen: Boolean read GetOpen;
        property Size: Integer read FSize;
      end;
    
    function ProcessFiles: Boolean;
    
    implementation
    
    var
      Files: TList;
    
    function ProcessFiles: Boolean;
    var
      i: Integer;
      AsyncFile: TAsyncFile;
    begin
      Result := False;
      for i := Files.Count - 1 downto 0 do
      begin
        AsyncFile := TAsyncFile(Files[i]);
        Result := AsyncFile.ProcessIo or Result;
      end;
    end;
    
    procedure Cleanup;
    var
      i: Integer;
      AsyncFile: TAsyncFile;
    begin
      for i := Files.Count - 1 downto 0 do
      begin
        AsyncFile := TAsyncFile(Files[i]);
        AsyncFile.Free;
      end;
      Files.Free;
    end;
    
    { TAsyncFile }
    
    constructor TAsyncFile.Create(Filename: string; BufferSize: Integer);
    begin
      Files.Add(Self);
      FReadPending := False;
      FBufferSize := BufferSize;
      GetMem(FBuffer, FBufferSize);
      FillMemory(@FOverlapped, SizeOf(FOverlapped), 0);
    
      Cardinal(FHandle) := CreateFile(
                      PChar(Filename),         // file to open
                      GENERIC_READ,            // open for reading
                      0,                       // do not share
                      nil,                     // default security
                      OPEN_EXISTING,           // open existing
                      FILE_ATTRIBUTE_NORMAL, //or // normal file
                      //FILE_FLAG_OVERLAPPED,    // asynchronous I/O
                      0);                      // no attr. template
    
      FSize := FileSeek(FHandle, 0, soFromEnd);
      FileSeek(FHandle, 0, soFromBeginning);
      FPosition := 0;
    end;
    
    destructor TAsyncFile.Destroy;
    begin
      Files.Remove(Self);
      CloseHandle(FHandle);
      FreeMem(FBuffer);
      inherited;
    end;
    
    function TAsyncFile.ProcessIo: Boolean;
    var
      ReadCount: Cardinal;
    begin  
      Result := False;  Exit;
      if not FReadPending then
      begin
        Exit;
      end;
    
      if GetOverlappedResult(FHandle, FOverlapped, ReadCount, False) then
      begin
        FReadPending := False;
        DoOnRead(ReadCount);
      end
      else
      begin
        case GetLastError() of
          ERROR_HANDLE_EOF:
          begin
            FReadPending := False;
            FEof := True;
          end;
          ERROR_IO_PENDING:
          begin
            FReadPending := True;
          end;
          0:
          begin
            Result := True; 
          end;
        end;
      end;
    end;
    
    procedure TAsyncFile.BeginRead;
    var
      ReadResult: Boolean;
      ReadCount: Cardinal;
    begin
      ReadCount := 0;
      Seek(FPosition);
      ReadResult := ReadFile(FHandle, FBuffer^, FBufferSize, ReadCount, nil);//@FOverlapped);
      if ReadResult then
      begin
        FEof := False;
        FReadPending := False;
        FPosition := FPosition + ReadCount;
        DoOnRead(ReadCount);
      end
      else
      begin
        case GetLastError() of
          ERROR_HANDLE_EOF:
          begin
            FReadPending := False;
            FEof := True;
          end;
          ERROR_IO_PENDING:
          begin
            FReadPending := True;
          end;
        end;
      end;
    end;
    
    procedure TAsyncFile.DoOnRead(Count: Integer);
    begin
      if Assigned(FOnRead) then
      begin
        FOnRead(Self, FBuffer^, Count);
      end;
    end;
    
    function TAsyncFile.GetOpen: Boolean;
    begin
      Result := Integer(FHandle) >= 0;
    end;
    
    procedure TAsyncFile.Close;
    begin
      FileClose(FHandle);
    end;
    
    procedure TAsyncFile.Seek(Position: Integer);
    begin
      FPosition := Position;
      FileSeek(FHandle, Position, soFromBeginning);
    end;
    
    initialization
      Files := Tlist.Create;
    
    finalization
      Cleanup;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
I found this article on how to manipulate the rendering sequence of asp.net controls.:
This article says If an object has a finalizer, it is not immediately removed
Based on this drag/drop article: http://delphi.about.com/od/adptips2005/qt/dropontimage.htm I'm trying to catch an image dragged from
I have written an ASP.NET web application (not site) in Delphi Prism. Everything works
This article on Binary-compatible C++ Interfaces contains the code: class Window { public: //
This article describes selecting it for .NET 3.5 under VS2008. How does one select
This article says that Emacs has redo because you can reverse direction while undoing,
This article from Microsoft details how to implement transport security with an anonymous client
This article on MSDN states that you can use as many try catch blocks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.