Question:
how can I get a disconnect event like "sftp.OnAbortCheck := sftpAbortCheck;" in ActiveX, please.
I'm using Delphi non-Active-X Version and can't find out how to catch events in that version. (sry, I'm new with that)
Unfortunately, event callbacks don't exist in the non-ActiveX Delphi DLL. I don't know of a way (yet?) to call back from native C++ into a Delphi app. I would imagine there's a way to do it since the ActiveX COM infrastructure provides that ability.
Thus, at this time, there are two Delphi options: (1) The ActiveX w/ event callbacks, but the drawback is that the ActiveX DLL needs to be registered (regsvr32) on any computer where it runs, or (2) The Delphi DLL which needs no regsvr32 registration, but has no callbacks.
callbacks from C++ to delphi can be done as in following example. in the example there is also a "tag"-param, which allows in the delphi-code the reentrance into the object (from __callback_Register_OnClose into TForm213.Nfy_OnClose).
hope this helps. if I can help more, please do not hesitate to contact me directly.
------------------------------ c++ code:
//type-definition for callback func
extern "C" typedef void ( TFktRegisterOnClose)( void * a__tag, int handle, char a_value);
//function to register callback
extern "C" __declspec(dllexport)void Register_OnClose( TFkt_Register_OnClose a_fkt, void * a_callback_tag);
//Test-Function
extern "C" __declspec(dllexport)void DoTest( int v1, int v2);
//global defined variables - here for Demonstration
TFkt_Register_OnClose glob_fkt = (TFkt_Register_OnClose)0;
void * glob_callback_tag = (void *) 0;
void Register_OnClose( TFkt_Register_OnClose a_fkt, void * a_callback_tag)
{
glob_fkt= a_fkt;
glob_callback_tag = a_callback_tag;
}
void DoTest( int v1,int v2)
{
int handle = 88;
// now doing the callback
if( glob_fkt)
(* glob_fkt)( glob_callback_tag, handle, "some callback test");
}
-------------------------------- Delphi-code: unit Unit213;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type TForm213 = class(TForm)
procedure FormCreate(Sender: TObject);
private
procedure Nfy_OnClose(Sender: TObject; handle:Integer; a_value:String);
public end;
var Form213: TForm213;
implementation
{$R *.dfm}
const DLLName= 'C:\projectstst_dlldebugtst_dll.dll';
type TFkt_Register_OnClose= procedure( a_tag:Pointer; handle:Integer; a_value:PAnsiChar); cdecl;
procedure Register_OnClose( a_fkt:TFkt_Register_OnClose; a_tag:Pointer); cdecl; external DLLName;
procedure DoTest( v1:Integer; v2:Integer); cdecl; external DLLName;
procedure __callback_Register_OnClose( a_tag:Pointer; handle:Integer; a_value:PAnsiChar); cdecl;
var
frm: TForm213;
begin
frm:= TForm213( a_tag);
frm.Nfy_OnClose( frm, handle, a_value);
end;
procedure TForm213.Nfy_OnClose(Sender: TObject; handle:Integer; a_value:String);
begin
ShowMessage( a_value);
end;
procedure TForm213.FormCreate(Sender: TObject);
begin
Register_OnClose( __callback_Register_OnClose, Self);
DoTest( 2,4);
end;
end.
Thanks! I'll see what can be done, but I can't promise anything at the moment..