When you say “outside the stream” and “inside the stream”, you mean “as an autonomous function” and “as a member of a stream object”? Since, if the function is a member of the object, its signature is different, therefore, it does not correspond to the expected compiler.
The way to resolve this issue is to pass Self to CopyFileEx as the lpData parameter. This gives him a pointer that he will return to the callback. Write your callback as a separate function that interprets the lpData parameter as a reference to a stream object and uses this to call a method in your stream object with the same parameters.
EDIT: A simple example. Let's say that the callback has only two parameters: "value" and "lpData":
procedure ProgressRoutine(value: integer; lpData: pointer); stdcall; var thread: TMyThreadClass; begin thread := lpData; thread.ProgressRoutine(value); end; procedure TMyThreadClass.ProgressRoutine(value: integer); begin //do something with the value here end; procedure TMyThreadClass.Execute; begin CopyFileEx(pchar(ListToCopy.Strings[Loop]),pchar(TN+ExtractFileName(ListToCopy.Strings[Loop])), @ProgressRoutine, Self, nil, 0); //passing Self to lpData; it will get passed back to the callback end;
Mason wheeler
source share