200分 怎么样获取子窗体的个数!(简单吗!不简单进来看看就知道了)这个问题我搞了很久了,恳请大家帮帮忙!(200分)

  • 主题发起人 你若有情
  • 开始时间

你若有情

Unregistered / Unconfirmed
GUEST, unregistred user!
呵呵!进来了!
是这样的,主窗体mainForm,子窗体是Dll中的子窗体!代码是这样的
library prDll;
{ 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,
ChildUnit in 'ChildUnit.pas' {ChildForm};
{$R *.res}
exports
ShowForm;
end.

unit ChildUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, DBGrids, StdCtrls, adodb, db;
type
TChildForm = class(TForm)
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
ChildForm: TChildForm;
function ShowForm(OwnerForm: TForm): integer;
stdcall;
implementation
{$R *.dfm}
function ShowForm(OwnerForm: TForm): integer;
var
ptr: PLongInt;
begin
ptr := @(Application.MainForm);
ptr^ := LongInt(OwnerForm);
ChildForm := TChildForm.Create(application);
end;

procedure TChildForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//FreeAndNil(dm_Total);
Action := caFree;
end;
end.

主窗体
unit frmMainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, DBGrids, StdCtrls, adodb, db;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button3: TButton;
Button1: TButton;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
function ShowForm(OwnerForm: TForm): integer;
stdcall;
external 'prDll.dll';
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//FreeAndNil(Application);
Action := caFree;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Showmessage(IntToStr(SElf.MDIChildCount));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
showForm(application.MainForm);
end;
end.

我在主窗体中获取个数,总是为0!代码有没有错,不知道
 
enumchildwindow();
 
function ShowForm(OwnerForm: TForm): integer;
var
ptr: PLongInt;
begin
ptr := @(Application.MainForm);
ptr^ := LongInt(OwnerForm);
ChildForm := TChildForm.Create(application);
end;

上面的 ptr 是干什么用的。
要建立多个子窗口不能用一个变量 childform
如果其它代码没有问题,如下改:
function ShowForm(OwnerForm: TForm): integer;
begin
application.handle:=OwnerForm.handle;
with TChildForm.Create(application)
do
show;
end;
 
to jsxjd
这种方法根本行不通!出错
 
if not Assigned(frm_weituoshoufei) then
frm_weituoshoufei := Tfrm_weituoshoufei.Create(Application);
frm_weituoshoufei.Show;
//On Close
Action := caFree;
//Destory
frm_weituoshoufei := nil;
 
很难吗?我存了很久才有200分!是不是太少了!
不会解决不了吧!
 
to shbjkl
上面的那句写在哪里啊!好像那样是在MainForm中Use 了ChildForm的单元后,才能使用吧!
但是我的在DLL中啊,应该怎么做啊
 
在showForm(application.MainForm)函数中
你没有指定它的父窗体。
返回值,当然是零。


 
在没有关闭子窗体的前提下,直接关闭主窗体时,
根本不会执行子窗体里的OnClose语句!
但在不使用DLL的子窗体中,都会执行.
 
to troyliu
那应该是怎样写那个函数呢!
 
在线等啊!大哥哥们!
 
使用DLL调用Form当然没有子窗口数目了,自己编写记数程序。
 
定义一个计数器,产生一个累加一个。最古老有效的方法。
 
to 薛獅 a_mao_gong
这个方法我也想到了,难道真的没有简单的方法了吗?那很惨啊!
那当打开了很多子窗体时,直接关闭主窗体时,如果子窗体里用了DataMoudle里又会出错!好惨
关闭主窗体时又不会触发子窗体中的OnClose事件.怎么办啊
 

ChildForm := TChildForm.Create(application);
我想可能是ChildForm 建立时用了application,可以把主窗口的句柄做为参数
我这里的计算机上没有Delphi 所以不能帮你试一试
function ShowForm(OwnerForm: TForm): integer;
begin
ChildForm := TChildForm.Create(OwnerForm);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
showForm(self);
end;


或者在窗口中创建子窗体
 
to free_knight
您的方法不行,我试过
 
在DLL使用DataMoudle行不行啊
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=0562056
 
我做一下!
 
to jsxjd
谢谢!
 
顶部