Archived Forum Post

Index of archived forum posts

Question:

implement a method of callback

Mar 15 '16 at 08:58

i need implement a method of callback but i'm having problems in way like am implementing. Can someone help me?

procedure TfrmPrincipal.EnviarArquivo;
var
  intf: IDispatch;
  ftp2: OleVariant;
begin
  try
    intf := CreateOleObject('Chilkat95_0.Ftp2');
    ftp2 := intf;
    try

  // Callback
  ftp2.onProgressInfo := ftp_onProgressInfo;

  if ftp2.unlockComponent('unlocked') <> 1 then
    raise Exception.Create(ftp2.LastErrorText);

  ftp2.HostName := edtHostName.Text;
  ftp2.UserName := edtUserName.Text;
  ftp2.PassWord := edtPassWord.Text;
  ftp2.Port     := StrToInt(edtPort.Text);
  ftp2.Passive  := 1;

  if ftp2.Connect <> 1 then
    raise Exception.Create(ftp2.LastErrorText);

  if (ftp2.ChangeRemoteDir('IN') <> 1) then
    raise Exception.Create(ftp2.LastErrorText);

  if (ftp2.PutFile(odlgArquivo.FileName,
                  ExtractFileName(odlgArquivo.FileName)) <> 1) then
    raise Exception.Create(ftp2.LastErrorText);

  mmLog.Lines.Add('File sent!!!')
except
  on e:exception do
    mmLog.Lines.Add(e.Message);
end;

finally
    VarClear(ftp2);
  end;
end;

Answer

You can find event help/examples in the online reference documentation. For example, go to http://www.chilkatsoft.com/refdoc/delphiFtp2Ref.html and then scroll all the way to the bottom.

Also, the string you're passing to CreateObject is wrong. It should be:

CreateOleObject('Chilkat_9_5_0.Ftp2');
or better yet, the object creation should be:
var
obj: TChilkatFtp2;
...
begin
obj := TChilkatFtp2.Create(Self);
...
// When finished, free the object instance.
obj.Free();


Answer

thanks for answer, but my problem is implementation of callback event, i don't know how pass the event to ftp2!

The event is ProgressInfo.

I don't use TLB.pas.


Answer

Your program doesn't generate the event.

The "event callbacks" are just callbacks. They are callbacks from within the Chilkat DLL back to the Delphi application. The flow of control is like this:

  1. Your program calls a Chilkat method (such as ftp2.PutFile)
  2. The program's thread of execution is now inside the Chilkat PutFile method
  3. PutFile makes a callback to your Delphi's callback method.
  4. The programs thread of execution is now inside your Delphi's callback method.
  5. Your callback method returns.
  6. The program's thread of execution is now back inside the Chilkat PutFile method, continuing on..
  7. This can repeat many times -- until finally the ftp2.PutFile method returns, and the thread of execution is back inside your application, continuing with the statements that follow the call to PutFile.

I don't know how to setup the callback function without the TLB.pas. In other words, you should use Delphi to generate the wrappers (i.e. TLB.pas) so that you can use TChilkatFtp2 and setup callbacks in the prescribed way.