我通过调用dll中的form放置到trzpagecontrol控件上,但只要有dbGrid,就会报找不到父窗口,我指定了父窗口也报错?然后就是关闭程序时崩溃,郁闷啊!!!!!
另外一点就是不能Destroy掉sheet,何解啊?
哪位高手帮帮忙?
procedure LoadForm(DLLName:string;Form: string;Page:Boolean);
var
  DLLHandle: THandle;
  ShowForm: TShowForm;
  ZForm: TForm;
  i:integer;
  tab:TRzTabSheet;
begin
  DLLHandle := LoadLibrary(PChar(DLLName));  if DLLHandle = 0 then
    MessageBox(Handle, PChar('加载动态库' + DLLName + '错误!'#13#13), '系统提示', MB_OK or MB_ICONERROR)
  else
  begin
    @ShowForm := GetProcAddress(DLLHandle,'ShowForm');    if @ShowForm = nil then
    begin
      MessageBox(Handle, PChar('定位' + DLLName + '中的ShowForm接口函数错误!'#13#13), '系统提示', MB_OK or MB_ICONERROR);
      FreeLibrary(DLLHandle);
      DLLHandle := 0;
    end;    if (DllHandle <> 0) and Assigned(ShowForm) then
    begin
      ZForm := ShowForm(Handle,Form);
      if Page = False then
      begin
        ZForm.ShowModal;
        FreeLibrary(DLLHandle);
      end
      else
      begin
        if pagecontrol.Visible = false then
          pagecontrol.Visible := true;          i := FindTab(pagecontrol,Form);
          if i+1 > 0 then
          begin
            pagecontrol.Pages[i].TabVisible := True;
            pagecontrol.ActivePageIndex := i;
          end
          else
          begin
            tab := TRzTabSheet.Create(pagecontrol);
            tab.Name := Form;
            tab.Caption := ZForm.Caption;
            tab.PageControl := pagecontrol;
            ZForm.FormStyle := fsNormal;
            ZForm.BorderStyle := bsNone;
            ZForm.Parent := tab;  //这里定义了父窗口啊
            ZForm.ParentWindow := tab.Handle; //这里定义了父窗口句柄啊
            ZForm.Tag := tab.TabIndex;
            tab.InsertControl(ZForm);
            ZForm.ManualDock(tab);
            ZForm.Show;
            ZForm.WindowState := wsMaximized;
            ZForm.Align := alClient;
            pagecontrol.ActivePage := tab;
          end;
      end;
    end;
  end;
end;procedure Tfrm_main.PageControlClose(Sender: TObject;
  var AllowClose: Boolean);
begin
  Index := PageControl.ActivePageIndex;  if PageControl.PageCount <1 then
  begin
    PageControl.Pages[Index].Destroy;   //执行到这里总会报错
    PageControl.Visible := False;
  end;
end;dll的代码
function ShowForm(Handle:THandle;Form:string):TForm;stdcall;
begin
  try
    if Form = 'CopyConfig' then
    begin
      application.Handle := Handle;
      Result := Tfrm_copyconfig.Create(Application);
    end;    
  except
    Result := nil;
    exit;
  end;
end;exports
  ShowForm;

解决方案 »

  1.   

    我晕·~看了一半~~~
    lz你这个问题20分恐怕不行……首先:
    var ……
    ShowForm: TShowForm;
    ……
    @ShowForm := GetProcAddress(DLLHandle,'ShowForm');
    ……
    if (DllHandle <> 0) and Assigned(ShowForm) then
      begin
      ZForm := ShowForm(Handle,Form);
    没见过这么调用dll窗体的,如果窗体上啥都没有,能条用成功吗?
      

  2.   


    没有问题,我如果不用pagecontrol做为父窗体,直接shoumodal是没有什么问题的,即使dll中的窗体只是个空白都没有任何调用问题。
      

  3.   

    网上搜索一下DELPHI DLL封装窗体的方法...