前面写了个动态链接库里面有个窗体可以共享(资料上的),现在我想在主程序中把他提出来用,下面是实现其弹出对话框的函数。但我没有看明白返回值怎么是Tdatetime还有他只是函数没有执行啦怎样才能执行其代码?就是说怎样才能调出动态链库里的窗体,用比较简单的方法.下面这个好像是自已建个函数把他引出来。(1)、声明要引出的函数:
Function showcanlendar(AHandle:THandle;Acaption:string):Tdatetime;stdcall;
(2)、函数体:
Function showcanlendar(AHandle:THandle;Acaption:string):Tdatetime;
var
DLLForm:TDllForm;
begin
application.handle:=ahandle; DllForm:=TDllForm.create(application);
try
DllForm.caption:=acaption
dllform.showmodal;
resout:=dllform.caldllcalendar.calendardate;
finally
DllForm.Free;
end;
end;
Function showcanlendar(AHandle:THandle;Acaption:string):Tdatetime;stdcall;
(2)、函数体:
Function showcanlendar(AHandle:THandle;Acaption:string):Tdatetime;
var
DLLForm:TDllForm;
begin
application.handle:=ahandle; DllForm:=TDllForm.create(application);
try
DllForm.caption:=acaption
dllform.showmodal;
resout:=dllform.caldllcalendar.calendardate;
finally
DllForm.Free;
end;
end;
解决方案 »
- 此简单问题100分!!有能力的请关注下!
- 初学delphi,想问问delphi要不要虚拟机之类的东西支持?
- 为什么在自定义函数内不能使用系统函数
- 小问题 马上结贴 最近太穷了 一天只有10分
- 小问题:kylix该怎么念呢?
- 清空数据库后,怎样使自加字段归零?
- 支持delphi的INSTALLSHIELD 的最好的版本是什么
- 如何用delphi将树形数据库导出到excel表中
- 想学basm,有什么资料可以借鉴?
- 一个象绕口令的问题,不知道谁能理解?
- 没分了老大们!问题又比较急,急死人了。向各位高手求救!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 如何得到dxDBGrid中鼠标点击的单元格的值 ,在线等待,急!~~!~~!
Function showcanlendar(AHandle:THandle;Acaption:string):Tdatetime;stdcall;
----------dll dpr----------
library Project2;uses
SysUtils,
Forms,
Classes,
Unit2 in 'Unit2.pas' {DllForm};{$R *.res}Function showcanlendar(AHandle:THandle; Acaption:string):Tdatetime; stdcall;
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;exports
showcanlendar;
begin
end.
---------dll form-----------
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;type
TDllForm = class(TForm)
MonthCalendar1: TMonthCalendar;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
DllForm: TDllForm;implementation{$R *.dfm}procedure TDllForm.FormShow(Sender: TObject);
begin
Self.MonthCalendar1.Date := Now-1;
end;end.
--------test form--------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; Function showcanlendar(AHandle:THandle; Acaption:string):Tdatetime; stdcall; external 'Project2.dll';var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := FormatDateTime('YYYY-MM-DD HH:NN:SS', showcanlendar(Application.Handle, '12345'));
end;end.
主程序
声明:
Function showcanlendar(AHandle:THandle;Acaption:string):Tdatetime;stdcall;external 'you r.dll';
调用
showmessage(formatdatetime('yyyymmdd',showcanlendar(handle,'demo')));
直接的输出我想是不是只能自已建个相同的函数把DLL中的窗体函数引出来?