Event OnStatus in Synapse lazarus / 13-General ---------------------------------------------------------------------- katyan · 2006-09-20 12:52 Does anyone know how to use event OnStatus from Synapse? I want to do a ProgressBar to know how many bytes I have sent on ftp server. Here is an exapmle but it don't work. I'm sure I've done something wrong. http://www.ararat.cz/synapse/wiki/index.php?page=OnStatus ---------------------------------------------------------------------- theo · 2006-09-20 13:16 What doesn't work? Are you aware of the fact that TFTPSend has 2 Sockets : Sock and DSock ? See: http://synapse.ararat.cz/docs/help/ftpsend.TFTPSend.html#Sock ---------------------------------------------------------------------- katyan · 2006-09-21 11:18 I still don't know how to use it. Can you give me working example of how to use OnStatus event? What do I do... I have created new unit: unit Unit2; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, typinfo, blcksock; type callback = class   class procedure Status (Sender: TObject; Reason: THookSocketReason; const Value: String); end; implementation class procedure callback.Status(Sender: TObject; Reason: THookSocketReason;   const Value: String); var v: String; begin   if (reason=hr_writecount) then   v := getEnumName (typeinfo(THookSocketReason), integer(Reason)) + ' ' + Value; end; end. I Unit 1 I add to uses section Unit2, then..  Ftp.Sock.OnStatus:=callback.Status; When I want to compile I have an error: Error: Wrong number of parameters specified Hint: Found declaration: class callback.Status(TObject, THookSocketReason,const AnsiString) ---------------------------------------------------------------------- theo · 2006-09-21 13:04 I think it's easier this way: Code: [Select] { TMyFTP }  TMyFTP = class(TFTPSend)   private   protected     procedure DSockCallBack (Sender: TObject; Reason:  THookSocketReason; const  Value: string);   public     constructor Create;   published   end; {bla bla} implementation { TMyFTP } constructor TMyFTP.Create; begin   inherited Create;   DSock.OnStatus:=@DSockCallBack; end; procedure TMyFTP.DSockCallBack(Sender: TObject; Reason: THookSocketReason;   const Value: string); begin   //Do something end; ---------------------------------------------------------------------- AndreasEbert · 2013-03-07 08:57 Hey Guys, I am programming  with Synapse FTPSend, but actually in the first Step I guess I need to do that with Multithreading. The method "onStatus" doesn't work for me.. Or do someone see a mistake in the Source below? If i am uploading a small file, everything works fluent. But if i want to transmit a file larger than e.g. 5 MB the Programm doesnt react on any Input after 2-3 seconds, like its freezed. After uploading with FTPPutPutFile the programm reacts again. Please Help  Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,   ComCtrls, ExtCtrls, Buttons, ftpsend, blcksock, typinfo; type   { TForm1 }   TForm1 = class(TForm)     BitBtn1: TBitBtn;     BitBtn2: TBitBtn;     BitBtn3: TBitBtn;     GroupBox1: TGroupBox;     GroupBox2: TGroupBox;     Image1: TImage;     Label1: TLabel;     Label10: TLabel;     Label11: TLabel;     Label2: TLabel;     Label3: TLabel;     Label4: TLabel;     Label5: TLabel;     Label6: TLabel;     Label7: TLabel;     Label8: TLabel;     Label9: TLabel;     LabeledEdit1: TLabeledEdit;     Memo1: TMemo;     OpenDialog1: TOpenDialog;     Panel1: TPanel;     ProgressBar1: TProgressBar;     Timer1: TTimer;     procedure BitBtn1Click(Sender: TObject);     procedure BitBtn2Click(Sender: TObject);     procedure BitBtn3Click(Sender: TObject);     procedure Button1Click(Sender: TObject);     procedure Edit1Change(Sender: TObject);     procedure FormCreate(Sender: TObject);     procedure GroupBox1Click(Sender: TObject);     procedure Label4Click(Sender: TObject);     procedure Label7Click(Sender: TObject);     procedure Label9Click(Sender: TObject);     procedure LabeledEdit1Change(Sender: TObject);     procedure OpenDialog1Close(Sender: TObject);     procedure OpenDialog1Show(Sender: TObject);     procedure Timer1Timer(Sender: TObject);     procedure UpdateStatus(Sender: TObject; Reason: THookSocketReason; const Value: string);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   TFTPClient: TFTPSend;   myOK : Boolean;   myDateiname: String;   myRemoteDateiname: String;   myFileSize: Integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.UpdateStatus(Sender: TObject; Reason: THookSocketReason; const Value: string); begin  Application.ProcessMessages;  memo1.Append('Something happend'); end; procedure TForm1.BitBtn1Click(Sender: TObject); begin   Timer1.Enabled:=true;   Panel1.Visible:=true;   BitBtn1.Enabled:= false;   BitBtn2.Enabled:= false;   BitBtn3.Enabled:=false;   LabeledEdit1.Enabled:=false;   TFTPClient := TFTPSend.Create;   with TFTPClient do      begin      TargetHost := 'ftp.dummyftp.de';      TargetPort := '21';      UserName := 'myLogin';      Password := 'myPassword';      PassiveMode := true;      DirectFile := True;      DirectFileName := myDateiname;      DSock.NonBlockMode := True;      DSock.OnStatus:= @UpdateStatus;      Sock.OnStatus:= @UpdateStatus;      Timeout := 3000;      if Login then      begin         if ((myFileSize > 1) and (myRemoteDateiname <> '') and (myDateiname <> '')) then         begin                myOK := FtpPutFile('123.456.789.123','21', '/Data/' + myRemoteDateiname, myDateiname, 'myLogin', 'myPassword');                Logout;                Free;              if (myOK) then              begin                   ShowMessage('File on Server.');              end              else              begin                 ShowMessage('File not on Server.');              end;         end         else         begin              ShowMessage('Bitte wählen Sie eine Datei aus.');         end;       end       else         begin         // Filetransfer not successful         // ...         ShowMessage('Login Fehlgeschlagen');         end;      BitBtn1.Enabled:= true;      BitBtn2.Enabled:= true;      BitBtn3.Enabled:=true;      LabeledEdit1.Enabled:=true;      Panel1.Visible:=false;      end; end; procedure TForm1.BitBtn2Click(Sender: TObject); begin    OpenDialog1.Execute;    if OpenDialog1.FileName <> '' then   begin     LabeledEdit1.Text:=OpenDialog1.FileName;     label11.Caption:=OpenDialog1.FileName;     myDateiname:=label11.Caption;     label8.Caption:= ExtractFileName(OpenDialog1.FileName);     label9.Caption:= inttostr(FileSize(OpenDialog1.FileName));     myFileSize:= strtoint(label9.Caption);     if myFileSize > 1000 then     begin          label9.Caption:= FloatToStr(myFileSize / (1024));          label9.Caption:= Copy(label9.Caption,0,4) + ' KB';     end     else if myFileSize > 1000000 then     begin          label9.Caption:= FloatToStr(myFileSize / (1024*1024));          label9.Caption:= Copy(label9.Caption,0,4) + ' MB';     end     else if myFileSize > 1000000000 then     begin          label9.Caption:= FloatToStr(myFileSize / (1024*1024*1024));          label9.Caption:= Copy(label9.Caption,0,4) + ' GB';     end;     label10.Caption:= LowerCase(label8.Caption);     label10.Caption:= StringReplace(label10.Caption, 'ä','ae',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, 'Ä','ae',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, 'ö','oe',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, 'Ö','oe',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, 'ü','ue',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, 'Ü','ue',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, ' ','_',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, 'ß','ss',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, '?','_',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, '?','_',[rfReplaceAll]);     label10.Caption:= StringReplace(label10.Caption, '=','_',[rfReplaceAll]);     label10.Caption:= '' + inttostr(Trunc((Now - EncodeDate(1970, 1 ,1)) * 24 * 60 * 60))+ '_' + label10.Caption;     myRemoteDateiname:=label10.Caption;     // Zur Lesbarkeit Strings nach 20 Stellen abscheiden.     if Length(label10.Caption) > 20 then     begin       label10.Caption:= Copy(label10.caption,0,20) + ' ...';     end;     if Length(label11.Caption) > 20 then     begin       label11.Caption:= Copy(label11.caption,0,20) + ' ...';     end;     if Length(label8.Caption) > 20 then     begin       label8.Caption:= Copy(label8.caption,0,20) + ' ...';     end;   end; end; procedure TForm1.BitBtn3Click(Sender: TObject);   var     Antwort:integer;   begin     beep;     close(); end; procedure TForm1.FormCreate(Sender: TObject); begin   panel1.Left:=88;   panel1.Top:=128; end; procedure TForm1.OpenDialog1Show(Sender: TObject); begin   LabeledEdit1.Text:=''; end; end. Please Write to a.ebert@pbsconsulting.biz if you have any idea why it doesn't work as supposed. www.pbsconsulting.de/Uploader/Data/Project1.zip ---------------------------------------------------------------------- theo · 2013-03-07 10:27 You should not mix the convenience function FtpPutFile with your own object TFTPClient. Have a look at the source code of FtpPutFile. Use StoreFile http://synapse.ararat.cz/doc/help/ftpsend.TFTPSend.html#StoreFile And don't use the "with" statement. It is evil ---------------------------------------------------------------------- AndreasEbert · 2013-03-07 11:20 Thanks Theo. It works great. You're really a Hero Member.