我编写了一个动态库,在其中创建了一个TFrame对象。要求能够在主程序中把这个TFrame对象显示在TPanel组件中,目前的状态是无法显示TFrame对象,在动态库中修改TFrame的Width、Height属性可以使得TPanel的AutoSize属性起作用。请问如何编写代码另外,一个问题如何把TFrame的ParentFont属性设置成true时,执行TFrame.Parent:=panel时报“无法把Font对象赋给Font对象”function ShowDLLTestFrame4(panel:TForm):boolean;
begin
  Result:=false;
  dllFrame1:=TfrmDLLFrame.Create(Application);
  dllFrame1.Parent:=panel;
  result:=true;
end;

解决方案 »

  1.   

    Application是主程序传递进来的吗?
    如果是动态连接库的就会出问题
      

  2.   

    试试这个,我抄来的:)
    dll中创建TFrame的代码如下:function CreateAFrame(App: TApplication,AScreen:TScreen): TFrame;stdcall;
    var
      p: ^LongInt;
    begin
      Screen := AScreen;
      Application := App;
      p := @(Application.MainForm);
      p^ := LongInt(App.MainForm);
      Result := TfrmDLLFrame.Create(Application);
    end;第二个程序使用如下:function TFrom1.GetFrameFromDll : boolean;
    begin
      FFrameFromDll := CreateAFrame(Application,Screen);
      FFrameFromDll.parent := self;
      FFrameFromDll.Align := alClient;
    end;
      

  3.   

    readersm68(地主) ,您好!我按你提供的代码进行了测试,发现还是无法在主程序中显示在动态库中创建的TFrame对象。并且,还需把TFrame的ParentFont属性设置成true,否则执行TFrame.Parent:=panel时会报“无法把Font对象赋给Font对象”的错误。
      

  4.   

    function ShowDLLTestFrame4(panel:TForm):boolean;
    begin
      Result:=false;
      dllFrame1:=TfrmDLLFrame.Create(Panel);
      dllFrame1.Parent:=panel;
      result:=true;
    end