将事件添加到动态创建的对象 - Webcopy - TMS 软件
Add events to dynamically created objects - Webcopy - TMS Software
我正在尝试将事件添加到来自 TMS 软件的动态创建的名为 webcopy 的组件。该代码适用于添加到表单的静态组件,但如果我想创建一个动态组件,我将无法执行不同的事件。
除了部分事件 webcopy.OnFileDone
:
,下面的代码工作正常
public
{ Public declarations }
procedure delete_file_after_upload(Sender:TObject; idx:integer);
end;
procedure Tform2.delete_file_after_upload(Sender:TObject; idx:integer);
begin
showmessage('FILENAME"'+upload_filename+'" SUCCESSFULLY UPLOADED TO FTP');
deletefile(upload_filename);
end;
procedure upload_file_to_ftp(filename,ftp_host,ftp_port,ftp_user,ftp_password,ftp_directory:string);
var webcopy:Twebcopy;
begin
try
webcopy:=Twebcopy.Create(NIL);
Webcopy.Items.Clear;
with WebCopy.Items.Add do
begin
{upload_filename = global variable so i can delete it after succesfully uploading it to ftp}
upload_filename:=filename;
protocol := wpFtpUpload;
URL:=filename; // local file that is input
FTPHost := ftp_host;
FtpPort := strtoint(ftp_port);
FTPUserID := ftp_user;
FTPPassword := ftp_password;
TargetDir := ftp_directory; // path to use on FTP server
{after the uploading process is done I want to delete the file from pc}
webcopy.OnFileDone:= Form2.delete_file_after_upload;
end;
finally
WebCopy.Execute;
freeandnil(webcopy);
end;
end;
处理程序必须具有适当的签名。
事件处理程序的类型定义为
TWebCopyFileDone = procedure(Sender:TObject; idx:integer) of object;
因此,您的处理程序必须是某个 class 的方法(这就是 of object
的意思),并接受两个参数,TObject 和 Integer。
例如:
procedure TForm2.delete_file_after_upload(Sender:TObject; idx:integer);
begin
...
您还必须将方法声明添加到 TForm2
的 public
部分。
我正在尝试将事件添加到来自 TMS 软件的动态创建的名为 webcopy 的组件。该代码适用于添加到表单的静态组件,但如果我想创建一个动态组件,我将无法执行不同的事件。
除了部分事件 webcopy.OnFileDone
:
public
{ Public declarations }
procedure delete_file_after_upload(Sender:TObject; idx:integer);
end;
procedure Tform2.delete_file_after_upload(Sender:TObject; idx:integer);
begin
showmessage('FILENAME"'+upload_filename+'" SUCCESSFULLY UPLOADED TO FTP');
deletefile(upload_filename);
end;
procedure upload_file_to_ftp(filename,ftp_host,ftp_port,ftp_user,ftp_password,ftp_directory:string);
var webcopy:Twebcopy;
begin
try
webcopy:=Twebcopy.Create(NIL);
Webcopy.Items.Clear;
with WebCopy.Items.Add do
begin
{upload_filename = global variable so i can delete it after succesfully uploading it to ftp}
upload_filename:=filename;
protocol := wpFtpUpload;
URL:=filename; // local file that is input
FTPHost := ftp_host;
FtpPort := strtoint(ftp_port);
FTPUserID := ftp_user;
FTPPassword := ftp_password;
TargetDir := ftp_directory; // path to use on FTP server
{after the uploading process is done I want to delete the file from pc}
webcopy.OnFileDone:= Form2.delete_file_after_upload;
end;
finally
WebCopy.Execute;
freeandnil(webcopy);
end;
end;
处理程序必须具有适当的签名。
事件处理程序的类型定义为
TWebCopyFileDone = procedure(Sender:TObject; idx:integer) of object;
因此,您的处理程序必须是某个 class 的方法(这就是 of object
的意思),并接受两个参数,TObject 和 Integer。
例如:
procedure TForm2.delete_file_after_upload(Sender:TObject; idx:integer);
begin
...
您还必须将方法声明添加到 TForm2
的 public
部分。