WEB开发网
开发学院软件开发Delphi 一个值得大家来考虑的DLL问题 阅读

一个值得大家来考虑的DLL问题

 2006-02-04 13:47:02 来源:WEB开发网   
核心提示:在MDI窗体类型的编程中,主窗体(fsMDIForm)怎样调用子窗体(fsMDIChild,一个值得大家来考虑的DLL问题,此子窗体为DLL),以下是我的原代码:==DPR 单元代码program Mdiform;uses Forms, UMdiform in 'UMdiform.pas' {Ma

在MDI窗体类型的编程中,主窗体(fsMDIForm)怎样调用子窗体(fsMDIChild,此子窗体为DLL)。
以下是我的原代码:
==========================================================================================
DPR  单元代码

program Mdiform;

uses
  Forms,
  UMdiform in 'UMdiform.pas' {Mainform},
  UDM in 'UDM.pas' {GlobalDM: TDataModule},
  UFun in 'UFun.pas';

{$R *.res}

begin
  application.Initialize;
  Application.CreateForm(TMainform, Mainform);
  Application.Run;
end.
===============================================================================================

主窗体代码:
unit UMdiform;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Udm,StdCtrls;
type
 
  TMainform = class(TForm)
   Button1: TButton;
   procedure Button1Click(Sender: TObject);
   procedure FormCreate(Sender: TObject);
  private
   { Private declarations }
  public
   MyHandle:HWND;
   { Public declarations }
  end;

var
  Mainform: TMainform;

type
  T_ShowTestMng=function (var adm:TMainform) : Boolean; StdCall;

implementation
{$R *.dfm}

procedure TMainform.Button1Click(Sender: TObject);
var
  Lib_     :THandle;
  _ShowTestMng :T_ShowTestMng;
begin
  Lib_:=LoadLibrary(pchar('MdiChild.dll'));
  try
   @_ShowTestMng:=GetProcAddress(Lib_,'_ShowTestMng');
   if not(@_ShowTestMng=nil) then
    _ShowTestMng(Mainform);
  finally
   FreeLibrary(Lib_);
  end;
end;

procedure TMainform.FormCreate(Sender: TObject);
begin
 MyHandle:=Application.Handle;
end;

end.
==============================================================================================

子窗体DLL代码:
library MdiChild;

uses
  ShareMem,
  UMdiform,  //此单元为父窗体单元,在顶目设置中我已经设置了搜索此单元在路径。
  Forms,
  SysUtils,
  Classes,
  UChild in 'UChild.pas' {FrmChild};//FrmChild子窗体的FormStyle属性为FsMDIChild

{$R *.res}
function _ShowTestMng(var adm:TMainform) : Boolean; StdCall;
begin
  result:=true;
  Application.Handle:=adm.MyHandle;
  Application.CreateForm(TFrmChild,FrmChild);  //程序就出错在此:出错原因是:Cannot create form. No MDI Forms are currently active.
  FrmChild.Show;
end;

exports
   _ShowTestMng;
end.

Tags:一个 值得 大家

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接