Advertisement
paulgertzen

Untitled

May 9th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. library Project2;
  2.  
  3. { Important note about DLL memory management: ShareMem must be the
  4. first unit in your library's USES clause AND your project's (select
  5. Project-View Source) USES clause if your DLL exports any procedures or
  6. functions that pass strings as parameters or function results. This
  7. applies to all strings passed to and from your DLL--even those that
  8. are nested in records and classes. ShareMem is the interface unit to
  9. the BORLNDMM.DLL shared memory manager, which must be deployed along
  10. with your DLL. To avoid using BORLNDMM.DLL, pass string information
  11. using PChar or ShortString parameters. }
  12.  
  13. uses
  14. SysUtils,
  15. Classes,
  16. IdBaseComponent, IdComponent, IdTCPConnection,
  17. IdTCPClient, IdFTP;
  18.  
  19. {$R *.res}
  20.  
  21. Type
  22. TFTPContainer = Class(TObject)
  23. Private
  24. FIdFTP: TIdFTP;
  25. Public
  26. procedure FTPOnStatus(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string);
  27. Constructor Create;
  28. Destructor Destroy; override;
  29. End;
  30.  
  31. // create an instance and return it as an integer/handle
  32. Function Initialize : Integer; stdcall;
  33. Var FTPContainer : TFTPContainer;
  34. Begin
  35. FTPContainer := TFTPContainer.Create;
  36. Result := Integer(FTPContainer); // typecast FTPContainer as integer and return it
  37. End;
  38.  
  39. // free the instance (the user must supply the integer/handle which they got from the call to Initialize
  40. Procedure DeInitialize(Handle : Integer); stdcall;
  41. Begin
  42. TFTPContainer(Handle).Free; // typecast handle back to FTPContainer and free it
  43. End;
  44.  
  45. { CONNECT TO THE FTP SERVER }
  46. function FTPConnect(Handle : Integer; AHost: String; APort: Integer; AUserName, APassword: String; APassive: Boolean = True): Boolean; stdcall;
  47. Var FTPContainer : TFTPContainer;
  48. begin
  49. FTPContainer := TFTPContainer(Handle); // typecast handle back to FTPContainer
  50. with FTPContainer.FIdFTP do
  51. begin
  52. Host := AHost;
  53. Port := APort;
  54. Username := AUserName;
  55. Password := APassword;
  56. Passive := APassive;
  57. Connect;
  58.  
  59. if Connected then
  60. Result := True
  61. else
  62. Result := False;
  63. end;
  64. end;
  65.  
  66. { EVENTS }
  67. constructor TFTPContainer.Create;
  68. begin
  69. FIdFTP := TIdFTP.Create(nil);
  70. FIdFTP.OnStatus := FTPOnStatus;
  71. // assign the rest of the events here
  72. end;
  73.  
  74. destructor TFTPContainer.Destroy;
  75. begin
  76. FidFTP.Free;
  77. inherited;
  78. end;
  79.  
  80.  
  81. procedure TFTPContainer.FTPOnStatus(ASender: TObject;
  82. const AStatus: TIdStatus; const AStatusText: string);
  83. begin
  84. // do something
  85. end;
  86.  
  87. Exports
  88. Initialize,
  89. DeInitialize,
  90. FTPConnect;
  91.  
  92. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement