Главная страницаОбратная связьКарта сайта

Вызвать процедуру из DLL


//  Call DLL Program  (Normal Application Project) 
//  This example calls a Quick Report within a DLL. 
//  Author: Michael Casse. 
//  18-12-2001. 

unit uMain; 

interface 

uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  StdCtrls, Buttons; 

type 
  TForm1 = class(TForm) 
    btnClose: TBitBtn; 
    btnReport: TBitBtn; 
    procedure btnReportClick(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

procedure TForm1.btnReportClick(Sender: TObject); 
var 
  LibHandle: THandle; 
  fDisplaySampleReport: procedure; 
  begin 
    LibHandle := LoadLibrary("Report.dll"); 
    if LibHandle = 0 then 
      raise Exception.Create("Unable to Load DLL...") 
    else 
    begin 
      try @fDisplaySampleReport := GetProcAddress(LibHandle, "DisplaySampleReport"); 
        if @fDisplaySampleReport <> nil then 
          fDisplaySampleReport; // Invoke the Procedure within the DLL 
      except 
        on E: Exception do 
          ShowMessage("Exception error: " + E.Message); 
      end; 
    end; 
    FreeLibrary(LibHandle); // Free Memory Allocated for the DLL 
  end; 

  end. 

  //////////////////////////////////////////////// 
  // DLL Project 

library Report; 

uses  SysUtils, Classes, 
      uReport in "uReport.pas" {Form1}; 

procedure DisplaySampleReport; 
begin 
  Form1 := TForm1.Create(nil); 
  try 
    Form1.QuickRep1.Preview; 
  finally 
    Form1.Free; 
  end; 
end; 

exports  DisplaySampleReport; 

end.


Обсудить статью на форуме


Если Вас заинтересовала или понравилась информация по разработке на Delph - "Вызвать процедуру из DLL", Вы можете поставить закладку в социальной сети или в своём блоге на данную страницу:

Так же Вы можете задать вопрос по работе этого модуля или примера через форму обратной связи, в сообщение обязательно указывайте название или ссылку на статью!
   


Copyright © 2008 - 2024 Дискета.info