以下是源码,注释掉的那一行就是导致出错的根源,去掉它就ok,否则虽可编译通过,但在往form上放时就会报上面的错。不知真正的原因在哪?
谢谢指教!unit M_QJ;
interface
uses
  SysUtils, Classes, Controls, StdCtrls, Messages,DBCtrlsEh,ExtCtrls,
  Dialogs,Graphics,DateUtils;type
  TM_QJ = class(TWinControl)  private
    FQJ :TComboBox;
  public
    constructor Create(AOwner:TComponent);override;
    destructor destroy;override;
    { Public declarations }
  published
    property QJ:TCombobox read FQJ write FQJ;
    { Published declarations }
  end;procedure Register;implementation
//------------
procedure Register;
begin
  RegisterComponents('MyCls', [TM_QJ]);
end;//------------
constructor TM_QJ.Create(AOwner:TComponent);
var
  i:Integer;
begin
  inherited;
  FQJ:=TCombobox.Create(self);
  FQJ.parent:=self;
  FQJ.Items.Add('200503');    //!!!导致出错的行!!!
end;//------------
destructor TM_QJ.destroy;
begin
  FQJ.free;
  inherited;
end;end.

解决方案 »

  1.   

    试一下:
    constructor TM_QJ.Create(AOwner:TComponent);
    var
      i:Integer;
    begin
      inherited;
      FQJ:=TCombobox.Create(AOwner);
      FQJ.parent:=AOwner;
      FQJ.Items.Add('200503');    //!!!导致出错的行!!!
    end;
      

  2.   

    回 gzmhero(hihihi) :
      谢谢您关注,我按您的思路,做了以下两种,都可编译通过,但放在form上后就是两块区域,互不相干一样.即使想把FQJ那个combobox移动到TWinControl上都不行,后者总在前面. 不知道可不可以不用TWinControl,直接由TComboBox继承面来.  FQJ:=TCombobox.Create(self);
      FQJ.parent:=TWinControl(AOwner);
    ------------------------------
      FQJ:=TCombobox.Create(AOwner);
      FQJ.parent:=TWinControl(AOwner);
      

  3.   

    追踪了一下,发现TCombobox本身就是由TWinControl继承多次而来的,于是改成下面的样子,也可编译通过,但往form上放时会报错说"A call to an OS function failed". 
    真是奇怪啊!  那如果要封装基于TCombobox的组件是不是就没办法了呢?unit M_QJ;
    interface
    uses
      SysUtils, Classes, Controls, StdCtrls, Messages,ExtCtrls,
      Dialogs,Graphics,DateUtils;type
      TM_QJ = class(TCombobox)
      end;procedure Register;
    implementation//------------
    procedure Register;
    begin
      RegisterComponents('MyCls', [TM_QJ]);
    end;end.
      

  4.   

    TM_QJ = Class(TComBox)
    然后重载creat函数不行么 ?
      

  5.   

    我用向导做了个最简单的,可以编译通过,但在顶部的组件表中就是没有它! 究竟怎么回事呢?unit E_QJ;
    interface
    uses
      SysUtils, Classes, QControls, QStdCtrls;type
      TE_QJ = class(TComboBox)
      private
        { Private declarations }
      protected
        { Protected declarations }
      public
        { Public declarations }
      published
        { Published declarations }
      end;procedure Register;
    implementationprocedure Register;
    begin
      RegisterComponents('MyCls', [TE_QJ]);
    end;
    end.
      

  6.   

    我用直接从TComboBox继承的方式,已经基本ok了。
    但是,无论如何都无法把它变成平面的,即使不封装组件,放一个普通的ComboBox在form上也变不过来,请大伙教我一下,谢谢!  Parent.Ctl3D:=False;
      Ctl3D:=False;
    同时用上都无效的。
      

  7.   

    什么玩意儿,刚才都好好的,现在稀里糊涂地又不行了,又是一楼的问题,has no parent window!
    不可琢磨啊! 真是搞死人了.
      

  8.   

    bevelkind := bkflat,改为平面的。
      

  9.   

    To Jerry529:您的办法有效,谢谢. 
    但不明白的是,delphi在这里的Ctl3D又是干啥用的.总觉得delphi怪怪的.下面是调试成功的代码,简单地封装一下TcomboBox,再放一个它的实例到form上,运行form的效果就很奇怪,form上被挖去了一个洞,象碉堡的射击孔! 有举的朋友可以试试看,好奇怪哟!unit M_QJ;
    interface
    uses
      SysUtils, Classes, Controls, StdCtrls, Messages,ExtCtrls,
      Dialogs,Graphics,DateUtils,windows;type
      TM_QJ = class(TCombobox)
        constructor Create(AOwner:TComponent);override;
      end;procedure Register;
    implementation//--------------------
    procedure Register;
    begin
      RegisterComponents('MyCls', [TM_QJ]);
    end;//--------------------
    constructor TM_QJ.Create(AOwner:TComponent);
    begin
      inherited;
    end;
    end.
      

  10.   

    空洞的原因找到了,不是Combobox的错,是表单的TransparentColor惹的.