怎样创建像第9章中讲的那把窗体放到dll?请大家多多指导,我在线等。

解决方案 »

  1.   

    我看过,但是手头没有,不知道你说什么意思。如果你是问dll中怎么加窗体,你就做一个project,有窗体的,然后到最后把project改成dll就行了,不知道你问的是不是这个
      

  2.   

    问题说的不清楚,将窗体既可以放在Dll,也可以放在Package里。
      

  3.   

    不知《DELPHI 6开发人员指南》怎么样
      

  4.   

    我就是问在dll中怎么加窗体的,能说得详细点好吗?是不是在创建dll文件时加个窗体呢。
      

  5.   

    有两个单元,一个MAIN,一个包含一个日历的单元。代码分别如下:
    {
    Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
    }unit MainFfm;interfaceuses
      SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
      Forms, Dialogs, StdCtrls;type
      { First, define a procedural data type, this should reflect the
        procedure that is exported from the DLL. }
      TShowCalendar = function (AHandle: THandle; ACaption: String): TDateTime; StdCall;  { Create a new exception class to reflect a failed DLL load }
      EDLLLoadError = class(Exception);  TMainForm = class(TForm)
        lblDate: TLabel;
        btnGetCalendar: TButton;
        procedure btnGetCalendarClick(Sender: TObject);
      end;var
      MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.btnGetCalendarClick(Sender: TObject);
    var
      LibHandle   : THandle;
      ShowCalendar: TShowCalendar;
    begin  { Attempt to load the DLL }
      LibHandle := LoadLibrary('CALENDARLIB.DLL');
      try
        { If the load failed, LibHandle will be zero.
          If this occurs, raise an exception. }
        if LibHandle = 0 then
          raise EDLLLoadError.Create('Unable to Load DLL');
        { If the code makes it here, the DLL loaded successfully, now obtain
          the link to the DLL's exported function so that it can be called. }
        @ShowCalendar := GetProcAddress(LibHandle, 'ShowCalendar');
        { If the function is imported successfully, then set lblDate.Caption to reflect
          the returned date from the function. Otherwise, show the return raise
          an exception. }
        if not (@ShowCalendar = nil) then
          lblDate.Caption := DateToStr(ShowCalendar(Application.Handle, Caption))
        else
          RaiseLastWin32Error;                                                               
      finally
        FreeLibrary(LibHandle); // Unload the DLL.
      end;
    end;end.
    {
    Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
    }unit DLLFrm;interfaceuses
      SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
      Forms, Dialogs, Grids, Calendar;type  TDLLForm = class(TForm)
        calDllCalendar: TCalendar;
        procedure calDllCalendarDblClick(Sender: TObject);
      end;{ Declare the export function }
    function ShowCalendar(AHandle: THandle; ACaption: String): TDateTime; StdCall;implementation
    {$R *.DFM}function ShowCalendar(AHandle: THandle; ACaption: String): TDateTime;
    var
      DLLForm: TDllForm;
    begin
      // Copy application handle to DLL's TApplication object
      Application.Handle := AHandle;
      DLLForm := TDLLForm.Create(Application); 
      try
        DLLForm.Caption := ACaption;
        DLLForm.ShowModal;
        Result := DLLForm.calDLLCalendar.CalendarDate; // Pass the date back in Result
      finally
        DLLForm.Free;
      end;
    end;procedure TDLLForm.calDllCalendarDblClick(Sender: TObject);
    begin
      Close;
    end;end.
      

  6.   

    如果看来这个还不明白(相信有从附带光盘里的代码不会出现此情况)。我也可以发MAIL给你。
      

  7.   

    给我发一份吧,谢谢!我E-MAIL是:[email protected]
      

  8.   

    《DELPHI 8开发人员指南》都出来了,还看D5的?