找个一在DLL中封装MDI子窗体的例子,可以被调用了,但当再次调用了,又创建另一个同样的子窗体
请问该怎样避免重复创建相同的子窗体啊,
dll的源码如下:
--------------------------------
library jiemian;uses
  SysUtils,
  forms,
  Classes,
  Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
procedure showform;stdcall;
  var
  form:tform1;
  begin
  if form=nil then
    begin
     form:=tform1.Create(application);
     form.show;
    end
      else
      form.BringToFront;
  end;
exports
 showform;
begin
end.

解决方案 »

  1.   

    procedure TMainForm.Openmdiwin(Sender: TFormClass);
    Var
      iii:Integer;
      Frm:TForm;
    begin
        For iii:=0 to MainForm.MDIChildCount-1 Do Begin
            if MainForm.MDIChildren[iii].ClassType=Sender Then Begin
               Frm:=MainForm.MDIChildren[iii];
               if Frm.WindowState=wsMinimized then //為最小化
                  ShowWindow(Frm.handle,SW_SHOWNORMAL)
               Else
                  ShowWindow(Frm.handle,SW_SHOWNA);
               if (Not Frm.Visible) then Frm.Visible:=True;
               Frm.BringToFront;
               Frm.SetFocus;
               Exit;
            End;
        End;
        Frm:=TForm(Sender.NewInstance);
        Frm:=Frm.Create(Self);
        Frm.Show;
    end;把这个函数改到你的dll
      

  2.   


    var
    DLLForm procedure TMainForm.StateMnClick(Sender: TObject);
    type
      InvokeDLLForm =function (App: TApplication; Scr: TScreen):TForm;
    var
      DLLHandle: THandle;
      DLLSub: InvokeDLLForm;  hp:HWND;
      DllPath:string;
    begin
      if Assigned(DLLForm) then DLLForm.Show;
      hp:=0;
      hp:=FindWindow('TMySumForm','工作量统计');
      if hp <> 0 then
      begin
        if IsIconic(hp) then
          ShowWindow(hp, SW_RESTORE)
        else
          BringWindowToTop(hp);
          //SetForegroundWindow(hp);
      end else
      begin
        DllPath:=GetDLLPath('Sum');
        if DllPath='' then  Exit;
        DLLHandle := LoadLibrary(Pchar(DllPath));
        if DLLHandle <> 0 then
        begin
          @DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
          if Assigned(DLLSub) then
          begin
            DLLForm := DLLSub(Application, Screen );
            DLLForm.Show;
          end;
        end;
      end;
    end;
      

  3.   

    同步Screen对象,然后枚举Screen.Forms查找
      

  4.   

    各位:
    我的意思是想把一窗体封装在DLL里,由MDI父窗体调用而创建子窗体. anbangs(大邦) ( ):
    怎把你的函数加到DLL啊?我的DLL里没有TMainForm这变量啊.
    qinget(C#热恋中) :
    你的源码是DLL里面的吗?水平有限,可以解释一下吗
      

  5.   

    dll代码:调用的时候传入一个Adoconnection就可以了,需要带包编译\\1---ModuleDemo.dpr
    library ModuleDemo;{ 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,
      DemoFrm in 'DemoFrm.pas' {DemoForm};{$R *.res}
    exports
      CallModule;
    begin
    end.
    \\2---DemoFrm.pas
    unit DemoFrm;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,DB, ADODB, StdCtrls, Buttons, ExtCtrls;type
      TDemoForm = class(TForm)
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
        procedure SpeedButton1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      DemoForm: TDemoForm;
      procedure CallModule(ss:TADOConnection);stdcall;
    implementation{$R *.dfm}
    var  AdoConn:Pointer;
    procedure CallModule(SS:TADOConnection);
    begin
      AdoConn:=SS;
      if not Assigned(DemoForm) then
      DemoForm:=TDemoForm.Create(Application);
      DemoForm.BringToFront;
    end;
    procedure TDemoForm.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action:=cafree;
      DemoForm:=nil;
    end;procedure TDemoForm.FormCreate(Sender: TObject);
    begin
    //
    end;procedure TDemoForm.SpeedButton1Click(Sender: TObject);
    begin
      close;
    end;end.
      

  6.   

    if not Assigned(DemoForm) then
      DemoForm:=TDemoForm.Create(Application);就是你要的
      

  7.   


    IF  not  Assigned(DemoForm) then
       DemoForm:= TDemoForm.Create(self)
    else
       DemoForm.Show;