我自己没事做了一个小程序,也就是一个主程序通过菜单调用多个子模块(dll实现),每个子模块完成特定功能。
现在我想实现是:
调用一个子模块后,不退出,可以再调用另一个子模块,怎么实现??
我想实现的要求是不是多文档程序,不是很清楚.......希望提供一个思路.....
现在我想实现是:
调用一个子模块后,不退出,可以再调用另一个子模块,怎么实现??
我想实现的要求是不是多文档程序,不是很清楚.......希望提供一个思路.....
解决方案 »
- 精确打印edit位置问题
- 安装Delphi7提示bnf.exe是病毒,是不是杀毒软件误报?
- 循环将窗体上所有的Edit的Visible设为True?
- delphi人气为什么不如SQL SERVER
- 各位高手有什么经验和体会吗?
- SQL查询为什么会是这样的结果?
- 请问怎样用Delphi代码实现对数据库的备份和恢复?? 高分送!
- 为什么所有应用程序都打不开(直接双击应用程序)?
- delphi安装盘数据库连接问题
- 急救:MDIForm中如何对MDIChild寻址?
- 如果设置stringGrid中cell的格式? sorry.没多少分了
- Delphi语法中的with...do是什么意思?等同于C++或者Java的什么语法?
在子模塊內的窗體將showmodal 改為show;不就行了麼.既然你想實現這種功能,推荐用MDI!
否則打開多個子窗體時,找不到它的父窗體, 使屏幕一片混亂!
用mdi可以调用dll作为子窗口么?自己up
-------------------------------------
可以,调用DLL函数的时候传个APPLICATION参数即可
一两句话说不清,自己摸索,呵呵
unit dllpGlobalVar;interfaceuses
Forms;
var
DLLApplication: TApplication;procedure SaveDLLApp(app: TApplication); //保存DLL的APPLICATIONfunction FindChildForm(MainApplication: TApplication; sClassName: string
): Boolean; //查找MDI窗口implementationprocedure SaveDLLApp(app: TApplication);
begin
if not Assigned(DLLApplication) then
begin
DLLApplication := Application;
Application := app;
end;
end;function FindChildForm(MainApplication: TApplication; sClassName: string
): Boolean;
var
i: Integer;
begin
Result := False;
SaveDLLApp(MainApplication);
with Application.MainForm do
for i := 0 to (MDIChildCount - 1) do
if (MDIChildren[i].ClassName = sClassName) then
begin
MDIChildren[i].BringToFront;
Result := True;
Break;
end;
end;
end.
---------------------------------
{dll输出函数单元}
unit UntExportFunction;interfaceuses
Forms, DB, ADODB, Graphics, Windows, ComCtrls;//显示其中某个窗口
procedure ShowExampleForm(
MainApp: TApplication);
implementationprocedure ShowExampleForm(
MainApp: TApplication);
var
Child: TExampleForm;
begin
SaveDLLApp(MainApp);
adoCon := con;
if not FindChildForm(MainApp, 'TExampleForm') then
begin
Child := ExampleForm.Create(Application);
CurrentUser := strCurrentUser;
Child.Show;
end;
end;
----------------------------------------------------
{工程文件单元}
library DllprjHRM;{ 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
Sharemem,
SysUtils,
Forms,
Classes,
windows,
...
{$R *.res}procedure MyLibraryProc(Reason: integer);
begin
if Reason = DLL_PROCESS_DETACH then
if Assigned(DLLApplication) then
Application := DLLApplication;
end;exports
ShowExampleForm;
begin
DllProc := @MyLibraryProc;
end.---------------------------------
调用应该会了吧^_^
事件中写action:=caFree,然后把窗口指针置为nil。
请问为什么在应用程序关闭的时候会出错呢??
如何解决??
事件中写action:=caFree,然后把窗口指针置为nil。
请问为什么在应用程序关闭的时候会出错呢??
如何解决??
for i:=1 to count_num do
begin
freeLibrary(dll_form[i]);
end;
application.Terminate ;
唉,怎么办?每人帮帮我么?
dll里面的子窗口就跟平常的一样用
在DLL中建立一个TMDIChildForM
1 Dll中的MDIForm.FormStyle不用为fmMDIChild.
2 在CreateForm后写以下两句:
function ShowForm(mainForm:TForm):integer;stdcall
var
Form1: TForm1;
ptr:PLongInt;
begin
ptr:=@(Application.MainForm);//先把dll的MainForm句柄保存起来,也无须释放,只不过是替换一下
ptr^:=LongInt(mainForm);//用主调程序的mainForm替换DLL的MainForm。MainForm是特殊的WINDOW,它专门管理Application中的Forms资源.
//为什么不直接Application.MainForm := mainForm,因为Application.MainForm是只读属性
Form1:=TForm1.Create(mainForm);//用参数建立
end;
备注:参数是主调程序的Application.MainForm九 示例:
DLL源代码:
library Project2;uses
SysUtils,
Classes,
Dialogs,
Forms,
Unit2 in 'Unit2.pas' {Form2};{$R *.RES}
var
ccc: Pchar;procedure OpenForm(mainForm:TForm);stdcall;
var
Form1: TForm1;
ptr:PLongInt;
begin
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
Form1:=TForm1.Create(mainForm);
end;procedure InputCCC(Text: Pchar);stdcall;
begin
ccc := Text;
end;procedure ShowCCC;stdcall;
begin
ShowMessage(String(ccc));
end;exports
OpenForm;
InputCCC,
ShowCCC;
begin
end.调用方源代码:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
procedure OpenForm(mainForm:TForm);stdcall;External'project2.dll';
procedure ShowCCC;stdcall;External'project2.dll';
procedure InputCCC(Text: Pchar);stdcall;External'project2.dll';procedure TForm1.Button1Click(Sender: TObject);
var
Text: Pchar;
begin
Text := Pchar(Edit1.Text);
// OpenForm(Application.MainForm);//为了调MDICHILD
InputCCC(Text);//为了实验DLL中的全局变量是否在各个应用程序间共享
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ShowCCC;//这里表明WINDOWS 32位应用程序DLL中的全局变量也是在应用程序地址空间中,16位应用程序或许不同,没有做实验。
end;
----------------------------------------------
为什么不设置fsMDIChild?
我认为我所用的方法不是完全的mdi程序,因为子程序没有用fsMDIChild,我认为肯定是资源没有释放,但是具体的就不知道,希望大家讨论一下