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

  • 主题发起人 主题发起人 你若有情
  • 开始时间 开始时间
我是不用Dll的。
把你的整个做成一个单元。
不同的对象封装成一个类。然后调用。
我给你一个例子。
我自己做的。
你的邮件呢
 
to troyliu
谢谢 DinkySoft@163.com
 
发过去了,收到了吗,这个可是我做了一个月的
 
to zw84611
来自:bbkxjy, 时间:2001-6-13 14:16:00, ID:565038
对了,你要把主程序中的 Screen 对象也传给 Dll,替换 Dll 中的 Screen 对象,就跟 Application
一样处理.看看 TCustomGorm.GetMDIChildCount 这个方法,它是遍历 Screen 对象中的 Forms
列表,返回 Style 为 fsMDIChild 的 form 的数量.所以会有问题.
这句话,写我不知道怎么写,帮帮我
var
DLLApp: TApplication;
//DLLScreen:TSCreen;
function ShowDllForm(App:TApplication;
ACaption:String;
mScreen:TScreen):Longint;stdcall;
begin
Application := App;
//Screen:=mScreen;
//if not Assigned(frmChild) then
frmChild:=TfrmChild.Create(Application);
Result:=Longint(frmChild);
frmChild.Caption := ACaption;
frmChild.Show;
//Screen:=mScreen;
end;

procedure DLLUnloadProc(Reason : Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;//恢复
//Screen:=DLLScreen;
end;
end;

exports
ShowDllForm;
begin
DLLApp := Application;
//保存 DLL 中初始的 Application 对象
//DLLScreen:=Screen;
DLLProc := @DLLUnloadProc;
//保证 DLL 卸载时恢复原来的 Application
end.

 
以下是能得到 mdiChildCount ,但主程序退出时有点问题:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
function ShowForm(app: TApplication;sc:TScreen): integer;external 'formdll.dll'
procedure TForm1.Button1Click(Sender: TObject);
begin
showform(Application,Screen)
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage(inttostr(MDIChildCount));
showmessage(inttostr(Screen.formcount));
end;

end.



///////////////// DDDDDDLLLLLLLLLLLLLLLLLL/////////
library FormDll;
uses
SysUtils,
windows,
Classes,
forms,
MyForm in 'MyForm.pas' {ChildForm};
{$R *.RES}
var
DLLApp: TApplication;
procedure DLLUnloadProc(Reason : Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
end;
end;

function ShowForm(App:TApplication;sc:TScreen): integer;
var
i:integer;
begin
application:=App;
Screen:=sc;
for i:=0 to N do
if ch=nil then
begin
ch:=TChildForm.Create(nil);
// ch.parent:=application.mainform;
ch.tag:=i;
break;
end;
Result:=0;
end;

exports ShowForm;
var
i:integer;
begin
for i:=0 to N do
ch:=nil;
DLLApp := Application;
DLLProc := @DLLUnloadProc;
end.


unit MyForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TChildForm = class(TForm)
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const N=100;
var
ch:array[0..N] of TChildForm;
implementation
{$R *.DFM}
procedure TChildForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
ch[tag]:=nil;
end;

procedure TChildForm.FormCreate(Sender: TObject);
begin
inherited;
FormStyle := fsMDIChild;
end;

end.
 
传Screen有很多问题!如果DLL里有DataMoudle的话,但是可以取到MDIChildCount的个数,但是
有问题
 

完全是 Screen 的问题,把正面这行注释掉:Screen:=sc;
程序就可以正常退出,但 mdichildcount 得不到。
这一问题应该针对 Screen 去解决。
 
to jsxjd
procedure DLLUnloadProc(Reason : Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;//恢复
Screen:=sc;
//加一句可以正常退出,没问题,但是如果有DataMoudle就显示不了数据
end;
end;
 
library prjDLL;
{ 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,
Windows,
Forms,
childUnit in 'childUnit.pas' {frmChild},
ChildDM in 'ChildDM.pas' {DM: TDataModule};
{$R *.res}
var
DLLApp: TApplication;
DLLScreen:TScreen;
function ShowDllForm(App:TApplication;
ACaption:String;
sc:TScreen):Longint;stdcall;
begin
Application := App;
Screen:=sc;
if not Assigned(frmChild) then
frmChild:=TfrmChild.Create(Application);
Result:=Longint(frmChild);
frmChild.Caption := ACaption;
frmChild.Show;
end;

procedure DLLUnloadProc(Reason : Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;//恢复
Screen:=DLLScreen;
end;
end;

exports
ShowDllForm;
begin
DLLApp := Application;
//保存 DLL 中初始的 Application 对象
DLLScreen:=Screen;
DLLProc := @DLLUnloadProc;
//保证 DLL 卸载时恢复原来的 Application
end.

unit childUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, publicUnit, Grids, DBGridEh, DB, ADODB;
type
TfrmChild = class(TForm)
DataSource1: TDataSource;
DBGridEh1: TDBGridEh;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmChild: TfrmChild;
implementation
{$R *.dfm}

procedure TfrmChild.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
FreeAndNil(frmChild);
//action := caFree;
end;

end.


unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Menus, publicUnit, Grids, DBGridEh, DB, ADODB;
type
TfrmMain = class(TForm)
Panel1: TPanel;
Button2: TButton;
MainMenu1: TMainMenu;
N1: TMenuItem;
Button1: TButton;
procedure Button2Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
frmArray: array of TForm;
frmCount: Integer;
public
{ Public declarations }
procedure ChildClose(var message: TMESSAGE);
message SM_CHILD_CLOSE;
end;

var
frmMain: TfrmMain;
function ShowDllForm(App:TApplication;
ACaption:String;
sc:TScreen):Longint;stdcall;external 'prjDll.dll';
implementation
{$R *.dfm}

procedure TfrmMain.Button2Click(Sender: TObject);
begin
Showmessage(IntToSTr(Self.MDIChildCount));
end;

procedure TfrmMain.N1Click(Sender: TObject);
begin
ShowDllForm(Application,'子窗体',Screen);
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
frmCount:=0;
end;

procedure TfrmMain.ChildClose(var message: TMESSAGE);
begin
frmCount:=frmCount-1;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
frmArray[0].Close;
end;

end.
 
结了算了,效率还算可以,还是想转去看看package行不行
 

Similar threads

I
回复
0
查看
628
import
I
I
回复
0
查看
566
import
I
I
回复
0
查看
740
import
I
S
回复
0
查看
751
SUNSTONE的Delphi笔记
S
后退
顶部