我看了一些资料,但主要讲函数的调用,窗体的调用讲得很简单,看不明白(作者用一种太简单了,实在懒得再讲的口吻带了两句),哪位仁兄给我扫一下盲?

解决方案 »

  1.   

    《参透Delphi/Kylix》第654页到第657页讲的很清楚。你可以去书店找到这本书看一下。由于篇幅太长,请恕我无法在这里把那些内容敲出来。
      

  2.   

    给你个例子看看,或许你会明白(是MDI子窗体的调用).这如果会了,那普通窗体的调用就更简单啦!!!//主程序///////////////////unit MainUnit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ToolWin, ComCtrls, Menus, ImgList;type
      TMainForm = class(TForm)
        ToolBar1: TToolBar;
        ToolButton1: TToolButton;
        ToolButton2: TToolButton;
        ToolButton3: TToolButton;
        ImageList1: TImageList;
        procedure fgf1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }  public
        { Public declarations }
        procedure DllCall(Sender: TObject);
      end; T_ProvaChild = procedure (ParentApplication: TApplication; parentform: TForm); stdcall;var
      MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.DllCall(Sender: TObject);
    var
       DllHandle: THandle;
       ProcAddr: FarProc;
       ProvaChild: T_ProvaChild;
       str,str1,str2 : string;
    begin
       str := (Sender as TToolButton).Caption ;
       str1 := copy(str,1,pos('@',str)-1);      // str1:=ProjectDll //  DLL文件名
       str2 := copy(str,pos('@',str)+1,length(str));  //str2:=ProvaChild   DllHandle := LoadLibrary(PChar(str1));
       if DllHandle <> 0 then
       begin
         ProcAddr := GetProcAddress(DllHandle, PChar(str2));
         if  Assigned(ProvaChild) then
         begin
            ProvaChild := ProcAddr;
            ProvaChild(Application,Self);      
         end;
    //****  freelibrary(DllHandle);//注意!!!注!!!*************
       end;end;procedure TMainForm.fgf1Click(Sender: TObject);
    begin
    //DllCall;
    end;procedure TMainForm.FormCreate(Sender: TObject);
    begin
    toolbutton1.caption:= ProjectDll@ProvaChild;
    toolbutton1.OnClick := DllCall;
    end;end.//DLL文件/////////////////////////////////library ProjectDll;uses
      Windows,
      Messages,
      SysUtils,
      Classes,
      Graphics,
      Controls,
      Forms,
      Dialogs,
      ubasStatusaaRoom in 'ubasStatusaaRoom.pas' {FbasStatusaaRoom};procedure DLLUnloadProc(Reason: Integer); register;
    begin
      if Reason = DLL_PROCESS_DETACH then  Application:=DllApplication;
    end;procedure ProvaChild(ParentApplication: TApplication; ParentForm: TForm); export; stdcall;
    begin
     if not Assigned(FbasStatusaaRoom) then
      begin
       Application := ParentApplication;
       FbasStatusaaRoom := TFbasStatusaaRoom.Create(nil);
       FbasStatusaaRoom.MyParentForm := ParentForm;
       FbasStatusaaRoom.MyParentApplication := ParentApplication;
      end;
     FbasStatusaaRoom.Show;
    end;exports
      ProvaChild;
      begin
       DllApplication:=Application;
       DLLProc := @DLLUnloadProc;
    end.//其中的一个子窗体/////////////////////////unit ubasStatusaaRoom;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, ToolWin, ExtCtrls, DB, DBClient, ImgList, Grids,
      DBGridEh,ActiveX;type
      TFbasStatusaaRoom = class(TForm)
        Panel1: TPanel;
        StatusBar1: TStatusBar;
        ToolBar1: TToolBar;
        tbfirst: TToolButton;
        tbprev: TToolButton;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
        MyParentForm: TForm;
        MyParentApplication: TApplication;
      end;var
      FbasStatusaaRoom: TFbasStatusaaRoom;
    implementation{$R *.dfm}           procedure TFbasStatusaaRoom.FormClose(Sender: TObject;
      var Action: TCloseAction);
    begin
    action := caFree;
    FbasStatusaaRoom := nil ;
    end;
    end.