Delphi - Create SuperDll Continuous Updates

Delphi SuperDll

As a 5-year Delphi, Delphi has always been regarded as the king of desktop applications, and I believe other Delphis also think so.

However, slowly I found that the common way of Delphi development can cause a serious bloated code, especially in the case of large MDI projects, multi-person development at the same time.

For example, a Delphi commonly used business logic, data export to Excel, can be written as a common module placed in the business unit, sub-forms can be directly invoked when used, but in general, things are not only as simple as imagined, the idea of maintenance personnel is really hard to say.

Later, I had the idea of encapsulating common business logic functions in Delphi into DLL. All business logic can only be implemented in DLL. It is not allowed to write business logic directly in the system, but can only call DLL.

The advantage of doing so is that the same business functions will not be redeveloped, which greatly reduces the bloated code. At the same time, business logic developers and front-end developers are independent, which improves the development efficiency.

This is the origin of SuperDLL, which will be updated continuously in the future.

See the following code:

Update logs:

// Initialization

// Mail Sending

// FTP Upload and Download

// Data Export of cxGrid

  1 library SuperDll;
  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, Classes, Variants, Graphics, Controls, IdBaseComponent, IdComponent, IdFTP,
 15   IdFTPCommon, IdTCPConnection, IdTCPClient, IdMessage, IdMessageClient, IdSMTP, cxGrid,
 16   cxGridExportLink, ComObj,
 17   cxCustomData, cxGraphics,
 18   cxData, cxDataStorage, cxEdit, cxDBData, cxGridLevel,
 19   cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView,
 20   cxGridTableView, cxGridDBTableView;
 21 
 22 {$R *.res}
 23 
 24 function SuperDll_Init: Boolean; stdcall;
 25 begin
 26   Result := True;
 27 end;
 28 
 29 function SuperDll_Ftp_PutOrGet(vType: string; var vUserName: string; var vPassWord: string; var vHost: string; var vDir: string; var vDesFilePath: string; vSouFilePath: string): Boolean; stdcall; //2: FTP File upload and download
 30 var
 31   IdFtp: TIdFTP;
 32 begin
 33   IdFtp := TIdFTP.Create(nil);
 34   Result := False;
 35   try
 36     with IdFtp do
 37     begin
 38       if Connected then Disconnect;
 39       Username := vUserName;
 40       Password := vPassWord;
 41       Host := vHost;
 42       Port := 21;
 43       Connect;
 44       ChangeDir(vDir);
 45       TransferType := ftBinary;
 46       if vType = 'Put' then
 47       begin
 48         Put(vSouFilePath, ExtractFileName(vSouFilePath));
 49       end
 50       else if vType = 'Get' then
 51       begin
 52         Get(ExtractFileName(vDesFilePath), vDesFilePath, True);
 53       end;
 54     end;
 55   finally
 56     IdFtp.Disconnect;
 57     IdFtp.Free;
 58     Result := True;
 59   end;
 60 end;
 61 
 62 function SuperDll_EMail_Send(vSubject: string; var vFrom: string; var vRecipients: string; var vCCList: string; var vBccList: string; var vBody: string; var vAttachment: string; var vUsername: string; var vPassword: string; var vHost: string): Boolean; stdcall;
 63 var
 64   IdSMTP: TIdSMTP;
 65   IdMessage: TIdMessage;
 66 begin
 67   Result := False;
 68   IdSMTP := TIdSMTP.Create(nil);
 69   IdMessage := TIdMessage.Create(nil);
 70   try
 71     with IdMessage do
 72     begin
 73       Clear;
 74       Subject := vSubject;
 75       From.Text := vFrom;
 76       Recipients.EMailAddresses := vRecipients;
 77       CCList.EMailAddresses := vCCList;
 78       BccList.EMailAddresses := vBccList;
 79       Priority := TIdMessagePriority(4);
 80       if Trim(vAttachment) <> '' then
 81       begin
 82         TIdAttachment.Create(MessageParts, Trim(vAttachment));
 83       end;
 84       vBody := vBody + #13#10;
 85       vBody := vBody + #13#10;
 86       vBody := vBody + #13#10;
 87       vBody := vBody + #13#10;
 88       vBody := vBody + 'It is Auto Mail System,please do not reply this mail directly,thank you!';
 89       Body.Add(vBody);
 90     end;
 91 
 92     with IdSMTP do
 93     begin
 94       if Connected then Disconnect;
 95       AuthenticationType := atLogin;
 96       Port := 25;
 97       UserName := vUsername;
 98       Password := vPassword;
 99       Host := vHost;
100       Connect;
101     end;
102 
103     IdSMTP.Send(IdMessage);
104     IdSMTP.Disconnect;
105 
106     Result := True;
107   finally
108     IdSMTP.Free;
109     IdMessage.Free;
110   end;
111 end;
112 
113 function SaveCxGridToExcel(vCxGrid: TcxGrid; var vFullPathName: string): Boolean; stdcall;
114 begin
115   Result := False;
116   vCxGrid := TcxGrid.Create(nil);
117   ExportGridToExcel(vFullPathName, vCxGrid);
118   vCxGrid.Free;
119   Result := True;
120 end;
121 
122 function SaveCxGridToCSV(vCxGrid: TcxGrid; var vFullPathName: string): Boolean; stdcall;
123 begin
124   Result := False;
125 
126   ExportGridToText(vFullPathName + '.XLS', vCxGrid, True, True, ',', '', '', 'CSV');
127   Result := True; ;
128 end;
129 
130 exports
131   SuperDll_Init,
132   SuperDll_Ftp_PutOrGet,
133   SuperDll_EMail_Send,
134   SaveCxGridToExcel,
135   SaveCxGridToCSV;
136 
137 begin
138 end.

Tags: Delphi ftp Excel

Posted on Wed, 04 Sep 2019 23:19:30 -0700 by Rodders