|
TpFIBDataBase в DLL
#39464709
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
|
Devart так советует:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334. 335. 336. 337. 338. 339. 340. 341. 342. 343. 344. 345. 346. 347. 348. 349. 350. 351. 352. 353. 354. 355. 356. 357. 358. 359. 360. 361. 362. 363. 364. 365. 366. 367. 368. 369. 370. 371. 372. 373. 374. 375. 376. 377. 378. 379. 380. 381. 382. 383. 384. 385. 386. 387.
unit DLLMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, Db, MemDS, StdCtrls, ExtCtrls, DBCtrls, DBAccess,
MSAccess, Buttons;
type
TfmDllMain = class(TForm)
MSQuery: TMSQuery;
DBGrid: TDBGrid;
DataSource: TDataSource;
pnToolBar: TPanel;
Panel1: TPanel;
btOpen: TSpeedButton;
btClose: TSpeedButton;
DBNavigator: TDBNavigator;
MSConnection: TMSConnection;
procedure btOpenClick(Sender: TObject);
procedure btCloseClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure AssignConnection(MSConnection: TMSConnection); cdecl;
procedure ShowForm; cdecl;
procedure HideForms; cdecl;
implementation
{$IFNDEF FPC}
{$IFDEF CLR}
{$R *.nfm}
{$ELSE}
{$R *.dfm}
{$ENDIF}
{$ENDIF}
{$IFNDEF VER130}
{$IFNDEF VER140}
{$IFNDEF CLR}
{$DEFINE XPMAN}
{$R WindowsXP.res}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$IFDEF XPMAN}
uses
UxTheme;
{$ENDIF}
var
ExternalMSConnection: TMSConnection;
FormList: TList;
FormCount: integer;
procedure AssignConnection(MSConnection: TMSConnection); cdecl;
begin
ExternalMSConnection := MSConnection;
end;
procedure ShowForm; cdecl;
begin
with TfmDllMain.Create(Application) do begin
Inc(FormCount);
Caption:= IntToStr(FormCount) + '. ' + Caption;
MSConnection.AssignConnect(ExternalMSConnection);
MSQuery.Active := True;
Show;
end;
end;
procedure HideForms; cdecl;
begin
while FormList.Count > 0 do begin
TForm(FormList[0]).Free;
FormList.Delete(0);
end;
end;
procedure TfmDllMain.FormShow(Sender: TObject);
begin
FormList.Add(Self);
end;
procedure TfmDllMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FormList.Remove(Self);
Action := caFree;
end;
procedure TfmDllMain.btOpenClick(Sender: TObject);
begin
MSQuery.Open;
end;
procedure TfmDllMain.btCloseClick(Sender: TObject);
begin
MSQuery.Close;
end;
procedure TfmDllMain.FormCreate(Sender: TObject);
{$IFDEF XPMAN}
procedure UpdateStyle(Control: TWinControl);
var
Panel: TPanel;
i: integer;
begin
for i := 0 to Control.ControlCount - 1 do begin
if Control.Controls[i] is TSpeedButton then
TSpeedButton(Control.Controls[i]).Flat := False
else
if Control.Controls[i] is TDBNavigator then
TDBNavigator(Control.Controls[i]).Flat := False;
if Control.Controls[i] is TWinControl then begin
if (Control.Controls[i] is TPanel) then begin
Panel := TPanel(Control.Controls[i]);
Panel.ParentBackground := False;
Panel.Color := clBtnFace;
end;
UpdateStyle(TWinControl(Control.Controls[i]));
end;
end;
end;
{$ENDIF}
begin
{$IFDEF XPMAN}
if UseThemes then
UpdateStyle(Self);
{$ENDIF}
end;
initialization
FormCount:= 0;
FormList:= TList.Create;
finalization
HideForms;
FormList.Free;
end.
library MS_DLL;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
ShareMem,
SysUtils,
Classes,
DLLMain in 'DLLMain.pas' {fmDllMain};
exports
AssignConnection,
ShowForm,
HideForms;
var
SaveExit: pointer;
procedure DllExit;
begin
ExitProc := SaveExit;
end;
begin
// SaveExit := ExitProc;
// ExitProc := @DllExit;
end.
program MS_Exe;
uses
ShareMem,
Forms,
ExeMain in 'ExeMain.pas' {fmExeMain};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TfmExeMain, fmExeMain);
Application.Run;
end.
unit ExeMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Grids, DBGrids, Db, MemDS, DBCtrls, DBAccess, SdacVcl,
MSAccess, Buttons;
type
TfmExeMain = class(TForm)
MSConnection: TMSConnection;
MSConnectDialog: TMSConnectDialog;
pnToolBar: TPanel;
DBGrid: TDBGrid;
MSQuery: TMSQuery;
DataSource: TDataSource;
Panel2: TPanel;
btFreeDLL: TSpeedButton;
btLoadDLL: TSpeedButton;
btShowForm: TSpeedButton;
btHideForms: TSpeedButton;
DBNavigator: TDBNavigator;
Panel1: TPanel;
btConnect: TSpeedButton;
btDisconnect: TSpeedButton;
btOpen: TSpeedButton;
btClose: TSpeedButton;
procedure btLoadDLLClick(Sender: TObject);
procedure btFreeDLLClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btConnectClick(Sender: TObject);
procedure btDisconnectClick(Sender: TObject);
procedure btOpenClick(Sender: TObject);
procedure btCloseClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btShowFormClick(Sender: TObject);
procedure btHideFormsClick(Sender: TObject);
private
hDLL:HModule;
public
end;
TAssignMSConnection = procedure (MSConnection: TMSConnection); cdecl;
TShowForm = procedure; cdecl;
THideForms = procedure; cdecl;
var
fmExeMain: TfmExeMain;
implementation
{$IFNDEF FPC}
{$IFDEF CLR}
{$R *.nfm}
{$ELSE}
{$R *.dfm}
{$ENDIF}
{$ENDIF}
{$IFNDEF VER130}
{$IFNDEF VER140}
{$IFNDEF CLR}
{$DEFINE XPMAN}
{$R WindowsXP.res}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$IFDEF XPMAN}
uses UxTheme;
{$ENDIF}
procedure TfmExeMain.btLoadDLLClick(Sender: TObject);
var
AssignMSConnection: TAssignMSConnection;
begin
if hDLL = 0 then begin
hDLL := LoadLibrary('MS_DLL.dll');
if hDLL <> 0 then begin
@AssignMSConnection := GetProcAddress(hDLL, 'AssignConnection');
if @AssignMSConnection <> nil then
AssignMSConnection(MSConnection);
MessageDlg('DLL is loaded', mtInformation, [mbOk], 0);
end
else
MessageDlg('Cannot load DLL', mtError, [mbOk], 0);
end;
end;
procedure TfmExeMain.btShowFormClick(Sender: TObject);
var
ShowForm: TShowForm;
begin
if hDLL <> 0 then begin
@ShowForm := GetProcAddress(hDLL, 'ShowForm');
if @ShowForm <> nil then
ShowForm;
SetFocus;
end
else
MessageDlg('DLL is not loaded', mtError, [mbOk], 0);
end;
procedure TfmExeMain.btHideFormsClick(Sender: TObject);
var
HideForms: THideForms;
begin
if hDLL <> 0 then begin
@HideForms := GetProcAddress(hDLL, 'HideForms');
if @HideForms <> nil then
HideForms;
end
else
MessageDlg('DLL is not loaded', mtError, [mbOk], 0);
end;
procedure TfmExeMain.btFreeDLLClick(Sender: TObject);
begin
if hDLL <> 0 then begin
FreeLibrary(hDLL);
hDLL:= 0;
MessageDlg('DLL is unloaded', mtInformation, [mbOk], 0);
end
else
MessageDlg('DLL is not loaded', mtError, [mbOk], 0);
end;
procedure TfmExeMain.FormCreate(Sender: TObject);
{$IFDEF XPMAN}
procedure UpdateStyle(Control: TWinControl);
var
Panel: TPanel;
i: integer;
begin
for i := 0 to Control.ControlCount - 1 do begin
if Control.Controls[i] is TSpeedButton then
TSpeedButton(Control.Controls[i]).Flat := False
else
if Control.Controls[i] is TDBNavigator then
TDBNavigator(Control.Controls[i]).Flat := False;
if Control.Controls[i] is TWinControl then begin
if (Control.Controls[i] is TPanel) then begin
Panel := TPanel(Control.Controls[i]);
Panel.ParentBackground := False;
Panel.Color := clBtnFace;
end;
UpdateStyle(TWinControl(Control.Controls[i]));
end;
end;
end;
{$ENDIF}
begin
{$IFDEF XPMAN}
if UseThemes then
UpdateStyle(Self);
{$ENDIF}
hDLL:= 0;
end;
procedure TfmExeMain.btConnectClick(Sender: TObject);
begin
MSConnection.Connect;
end;
procedure TfmExeMain.btDisconnectClick(Sender: TObject);
begin
MSConnection.Disconnect;
end;
procedure TfmExeMain.btOpenClick(Sender: TObject);
begin
MSQuery.Open;
end;
procedure TfmExeMain.btCloseClick(Sender: TObject);
begin
MSQuery.Close;
end;
procedure TfmExeMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if hDLL <> 0 then
FreeLibrary(hDLL);
end;
end.
|
|
|