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 6025785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:21:02+00:00 2026-05-23T04:21:02+00:00

Is it possible and right to call CopyFileEx and CopyCallback/ProgressRoutine function (ProgressBar.Position will be

  • 0

Is it possible and right to call CopyFileEx and CopyCallback/ProgressRoutine function (ProgressBar.Position will be synchronized) from a thread?

Can I declare CopyCallback/ProgressRoutine function in a thread? I get Error: “Variable required” in CopyFileEx on @ProgressRoutine.

  • 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-05-23T04:21:03+00:00Added an answer on May 23, 2026 at 4:21 am

    Of course it’s possible. The callback function will be called in the context of the thread that calls CopyFileEx. If you need to synchronize some UI commands, use Delphi’s usual TThread.Synchronize, or whatever other inter-thread synchronization techniques you want.

    The callback function cannot be a method of the thread class. It needs to match the signature dictated by the API, so it needs to be a standalone function. When you’ve declared it correctly, you won’t need to use the @ operator when you pass it to CopyFileEx.

    function CopyProgressRoutine(TotalFileSize, TotalBytesTransferred: Int64;
      StreamSize, StreamBytesTransferred: Int64;
      dwStreamNumber, dwCallbackReason: DWord;
      hSourceFile, hDestinationFile: THandle;
      lpData: Pointer): DWord; stdcall;
    

    You can give the callback function access to the associated thread object with the lpData parameter. Pass a reference to the thread object for that parameter when you call CopyFileEx:

    procedure TCopyThread.Execute;
    begin
      ...
      CopyResult := CopyFileEx(CurrentName, NewName, CopyProgressRoutine, Self,
        @Cancel, CopyFlags);
      ...
    end;
    

    With access to the thread object, you can call methods on that object, including its own progress routine, so the following could constitute the entirety of the standalone function. It can delegate everything else back to a method of your object. Here I’ve assumed the method has all the same parameters as the standalone function, except that it omits the lpData parameter because that’s going to be passed implicitly as the Self parameter.

    function CopyProgressRoutine;
    var
      CopyThread: TCopyThread;
    begin
      CopyThread := lpData;
      Result := CopyThread.ProgressRoutine(TotalSize, TotalBytesTransferred,
        StreamSize, StreamBytesTransferred, dwStreamNumber,
        dwCallbackReason, hSourceFile, hDestinationFile);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to call a .NET method from PowerShell with early binding? I
Possible Duplicate: Where should I call Free() function? When I used valgrind --leak-check=full --show-reachable=yes
Possible Duplicates: How to use reflection to call generic Method? Select Right Generic Method
I'm trying to capture the call stack as quickly as possible. Right now this
Is it possible to make a call/notification to a C++ application from Microsoft SQL
Is it possible to make a call from a view to a controller via
In MS VisualStudio (I'm using 2005), it's possible to right-click in some code file
Is it possible to scroll down the left and right parts of a vertically
Is it possible to add a button to the right corner of the app
Is it possible, using actionscript 3 to disable the right click menu? Any help

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.