home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk15 / bdedll.pak / APPUNIT1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-08-24  |  1.9 KB  |  82 lines

  1. unit Appunit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons;
  8.  
  9. type
  10.   TAppForm1 = class(TForm)
  11.     OpenDialog1: TOpenDialog;
  12.     TableNameEdit1: TEdit;
  13.     OpenTableLabel1: TLabel;
  14.     SelectBtn1: TBitBtn;
  15.     ViewBtn1: TBitBtn;
  16.     BitBtn1: TBitBtn;
  17.     procedure SelectBtn1Click(Sender: TObject);
  18.     procedure BitBtn1Click(Sender: TObject);
  19.     procedure ViewBtn1Click(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   AppForm1: TAppForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. {
  34.   These definitions will cause the service DLL to load and initialize.
  35.   Alternatively, the DLL could be dynamically loaded and unloaded using
  36.   LoadLibrary and FreeLibrary.
  37. }
  38.  
  39. function UseDLL: string; far; external 'DLLPROJ1';
  40. procedure ExitDLL; far; external 'DLLPROJ1';
  41. function ViewTable (const TableName: string): string; far; external 'DLLPROJ1';
  42.  
  43. procedure TAppForm1.SelectBtn1Click(Sender: TObject);
  44. begin
  45.   if OpenDialog1.Execute then
  46.      TableNameEdit1.Text := OpenDialog1.FileName
  47. end;
  48.  
  49. procedure TAppForm1.BitBtn1Click(Sender: TObject);
  50. begin
  51.   Close;
  52. end;
  53.  
  54. procedure TAppForm1.ViewBtn1Click(Sender: TObject);
  55. var
  56.    DllResult: string;
  57. begin
  58.   DllResult := ViewTable (TableNameEdit1.Text);
  59.   if Length (DllResult) <> 0 then raise Exception.Create (DllResult);
  60. end;
  61.  
  62. {
  63.   Since we bind statically to the demo service DLL, we check that we can
  64.   can use it during initialization.  If we dynamically loaded the DLL via
  65.   LoadLibary, we would check at that time instead.
  66. }
  67.  
  68. procedure CheckDLLUse;
  69. var
  70.    DllResult: string;
  71. begin
  72.   DllResult := UseDll;
  73.   if Length (DllResult) <> 0 then raise Exception.Create (DllResult);
  74. end;
  75.  
  76. { The service DLL was initialized automatically, so it must be released }
  77.  
  78. begin
  79.   CheckDLLUse;
  80.   AddExitProc (ExitDLL);
  81. end.
  82.