DELPHI5指南上一例子
单击按钮调出日期选择窗体,双击MonthCalendar返回所选日期,并将日期赋给EDIT1
如下:应用程序过程
procedure TForm1.Button2Click(Sender: TObject);
var
libHandle:THandle;
SHowCalendar:TShowCalendar;
begin
libHandle:=Loadlibrary('DLLFrmp.dll');
try
if libHandle=0 then
begin
raise EDLLLoadError.Create('unable to load dll');
end;
@SHowCalendar:=GetProcAddress(libHandle,'ShowCalender');
if not(@ShowCalendar=nil) then
edit1.Text:=DateToStr(ShowCalendar(application.Handle,caption))
{这里出错,说不能创建模式窗体,我把DLL里的窗体FORMSTYLE属性改为FSSTAYONTOP,
窗体出现后就动不了了,进程都结束不了,只有重新启动}
else
showmessage('ok');
RaiselastWin32Error;
finally
Freelibrary(libHandle);
end;
end;DLL 中FORM代码nit DLLFrm;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;type
TDLLForm = class(TForm)
MonthCalendar1: TMonthCalendar;
procedure MonthCalendar1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
DLLForm: TDLLForm;
function ShowCalender(AHandle:THandle;ACaption:String):
TDatetime;StdCall;
implementation{$R *.dfm}
function ShowCalender(AHandle:THandle;ACaption:String):TDatetime;
var
DLLForm:TDllFORM;
begin
Application.Handle :=AHandle;
DLLForm:=TDLLForm.create(Application);
try
DLLForm.caption:=ACaption;
DLLForm.showmodal;
Result:=DLLForm.MonthCalendar1.Date;
finally
DLLForm.free;
end;
end;procedure TDLLForm.MonthCalendar1DblClick(Sender: TObject);
begin
close;
end;end.请高手指点。
单击按钮调出日期选择窗体,双击MonthCalendar返回所选日期,并将日期赋给EDIT1
如下:应用程序过程
procedure TForm1.Button2Click(Sender: TObject);
var
libHandle:THandle;
SHowCalendar:TShowCalendar;
begin
libHandle:=Loadlibrary('DLLFrmp.dll');
try
if libHandle=0 then
begin
raise EDLLLoadError.Create('unable to load dll');
end;
@SHowCalendar:=GetProcAddress(libHandle,'ShowCalender');
if not(@ShowCalendar=nil) then
edit1.Text:=DateToStr(ShowCalendar(application.Handle,caption))
{这里出错,说不能创建模式窗体,我把DLL里的窗体FORMSTYLE属性改为FSSTAYONTOP,
窗体出现后就动不了了,进程都结束不了,只有重新启动}
else
showmessage('ok');
RaiselastWin32Error;
finally
Freelibrary(libHandle);
end;
end;DLL 中FORM代码nit DLLFrm;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;type
TDLLForm = class(TForm)
MonthCalendar1: TMonthCalendar;
procedure MonthCalendar1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
DLLForm: TDLLForm;
function ShowCalender(AHandle:THandle;ACaption:String):
TDatetime;StdCall;
implementation{$R *.dfm}
function ShowCalender(AHandle:THandle;ACaption:String):TDatetime;
var
DLLForm:TDllFORM;
begin
Application.Handle :=AHandle;
DLLForm:=TDLLForm.create(Application);
try
DLLForm.caption:=ACaption;
DLLForm.showmodal;
Result:=DLLForm.MonthCalendar1.Date;
finally
DLLForm.free;
end;
end;procedure TDLLForm.MonthCalendar1DblClick(Sender: TObject);
begin
close;
end;end.请高手指点。
var
DLLForm:TDllFORM;
OldHandle : THandle;
begin
OldHandle := Application.Handle;
Application.Handle :=AHandle;
DLLForm:=TDLLForm.create(Application);
try
DLLForm.caption:=ACaption;
DLLForm.showmodal;
Result:=DLLForm.MonthCalendar1.Date;
finally
DLLForm.free;
Application.Handle := OldHandle;
end;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;type
TForm1 = class(TForm)
Button1: TButton;
DT1: TDateTimePicker;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;type
TGetDate = function (const AHandle : THandle; ACaption : String):TDate;stdcall;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var SGetDate : TGetDate;
LH : THandle;
begin
LH := LoadLibrary('Project2.dll');
if LH <> 0 then
@SGetDate := GetProcAddress(LH,'GetDate');
if @SGetDate <> nil then
try
Dt1.Date := SGetDate(Application.Handle,'sss');
finally
FreeLibrary(LH);
end;
end;end.dlllibrary Project2;{ 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
SysUtils,
Classes,
Controls,
Forms,
Unit2 in 'Unit2.pas' {Form1};
{$R *.res}function GetDate(Const AHandle : THandle; ACaption : String):TDate;stdcall;
var Form1 : TForm1 ;
OldHand : THandle ;
begin
OldHand := Application.Handle ;
Application.Handle := AHandle;
Form1 := TForm1.Create(Application);
Form1.ShowModal ;
Form1.Caption := ACaption;
Result := Form1.MonthCalendar1.Date ;
Application.Handle := OldHand;
Form1.Free;end;exports
GetDate;begin
end.
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, Calendar, ComCtrls;type
TForm1 = class(TForm)
MonthCalendar1: TMonthCalendar;
procedure MonthCalendar1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}
procedure TForm1.MonthCalendar1DblClick(Sender: TObject);
begin
Self.Close ;
end;end.
是因为DLL表单的visible属性问题应该设置为false.多谢几位热情相助,给分。