向大家请教(100分)

  • 主题发起人 主题发起人 LinSen
  • 开始时间 开始时间
L

LinSen

Unregistered / Unconfirmed
GUEST, unregistred user!
向在大家请教,怎么把一个单元文件转化为动态链接库。然后又怎么在另外一个单元中引用该单元。
 
你是那种无窗体的UNIT吧, 呵呵:) 直接写成DLL就行了吗。
 
怎么把单一个单元文件转化为动态链接库,然后又怎么在另外一个单元引用该单元(要像使用单元一样随意反问该动态库接库中的一切对象)
 
我也想知到...
 
生成可以用向导,把要用的export。用时 如 function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer;
stdcall;
external 'KERNEL32.DLL';样式,在使用该dll的单元中使用即可。
 
{
Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
}
unit MainFfm;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TMainForm = class(TForm)
btnShowCalendar: TButton;
btnCloseCalendar: TButton;
procedure btnShowCalendarClick(Sender: TObject);
procedure btnCloseCalendarClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FFormRef: TForm;
end;

var
MainForm: TMainForm;
function ShowCalendar(AHandle: THandle;
ACaption: String): Longint;
StdCall;
external 'CALENDARMLLIB.DLL';
procedure CloseCalendar(AFormRef: Longint);
stdcall;
external 'CALENDARMLLIB.DLL';
implementation
{$R *.DFM}
procedure TMainForm.btnShowCalendarClick(Sender: TObject);
begin
if not Assigned(FFormRef) then
FFormRef := TForm(ShowCalendar(Application.Handle, Caption));
end;

procedure TMainForm.btnCloseCalendarClick(Sender: TObject);
begin
if Assigned(FFormRef) then
begin
CloseCalendar(Longint(FFormRef));
FFormRef := nil;
end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
FFormRef := nil;
// Initialize the FFormRef field to nil.
end;

end.

{
Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
}
unit DLLFrm;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Grids, Calendar;
type
TDLLForm = class(TForm)
calDllCalendar: TCalendar;
end;

{ Declare the export function }
function ShowCalendar(AHandle: THandle;
ACaption: String): Longint;
stdCall;
procedure CloseCalendar(AFormRef: Longint);
stdcall;

implementation
{$R *.DFM}
function ShowCalendar(AHandle: THandle;
ACaption: String): Longint;
var
DLLForm: TDllForm;
begin
// Copy application handle to DLL's TApplication object
Application.Handle := AHandle;
DLLForm := TDLLForm.Create(Application);
Result := Longint(DLLForm);
DLLForm.Caption := ACaption;
DLLForm.Show;

end;

procedure CloseCalendar(AFormRef: Longint);
begin
if AFormRef > 0 then
TDLLForm(AFormRef).Release;
end;

end.
 
接受答案了.
 
后退
顶部