代码片断unit c_DataStru;interfaceuses
   Classes, controls, dxEdLib, stdCtrls;type
   TMySubItem =Class
    Private
      m_value: variant;
      m_name : TComponentName;
      m_type : Byte;
      m_Control: TControl;    Public
      Constructor  Create(f_name:string; f_type:Byte; _owner:TComponent; _parent:TWinControl);
      DeStructor   Destroy();
      Procedure    SetParent( _parent:TWinControl);
end;implementationConst
        _Label    : Byte =0;
        _dxEdit   : Byte =1;
        _dxCheckEdit : Byte =2;
Procedure    TMySubItem.SetParent( _parent:TWinControl);
begin
  case  m_type of
    _Label    ://报错
        begin
          (m_Control as TLabel).Parent:=_parent;
        end;
    _dxEdit   :
        begin
          (m_Control as TdxEdit).Parent:=_parent;
        end;
    _dxCheckEdit :
        begin
          (m_Control as TdxCheckEdit).Parent:=_parent;
        end;
  end;
end;

解决方案 »

  1.   

    不要使用_开头看看?
    使用my_label,my_dxedit,my_cxcheckedit.
      

  2.   

    type
      TMyType = (my_Label, my_dxedit, my_cxcheckedit);  TMySubItem =Class
        Private
          m_value: variant;
          m_name : TComponentName;
          m_type : TMyType;
          m_Control: TControl;    Public
          Constructor  Create(f_name:string; f_type:Byte; _owner:TComponent; _parent:TWinControl);
          DeStructor  Destroy();
          Procedure    SetParent( _parent:TWinControl);
    end;implementation
      

  3.   

    unit c_DataStru;interfaceuses
       Classes, controls, dxEdLib, stdCtrls;type
       TControltype = (_Label,_dxEdit,_dxCheckEdit);//自定义
       TMySubItem =Class
        Private
          m_value: variant;
          m_name : TComponentName;
          m_Control: TControl;
          m_type  : TControltype;    Public
          Constructor  Create(f_name:string; f_type:Byte; _owner:TComponent; _parent:TWinControl);
          DeStructor   Destroy();
          Procedure    SetParent( _parent:TWinControl);
    end;
    implementation
    {
    Const
            _Label    : Byte =0;
            _dxEdit   : Byte =1;
            _dxCheckEdit : Byte =2;}
    Procedure    TMySubItem.SetParent( _parent:TWinControl);
    begin
      case  m_type of
        _Label    :
            begin
              (m_Control as TLabel).Parent:=_parent;
            end;
        _dxEdit   :
            begin
              (m_Control as TdxEdit).Parent:=_parent;
            end;
        _dxCheckEdit :
            begin
              (m_Control as TdxCheckEdit).Parent:=_parent;
            end;
      end;
    end;Constructor  TMySubItem.Create(f_name:string; f_type:byte; _owner:TComponent);
    //构造时f_type定成byte m_type:=f_type 报错
    //构造时f_type定成Tcontroltype m_type:=f_type 还是报错
    begin
      inherited Create();
      m_type:= f_type;
      m_Control.Parent:=_parent;  case  m_type   of
        _Label    :
            begin
              m_Control:=(TLabel.Create(_owner) as TControl);
            end;
        _dxEdit   :
            begin
              m_Control:=(TdxEdit.Create(_owner) as TControl);
            end;
        _dxCheckEdit :
            begin
              m_Control:=(TdxCheckEdit.Create(_owner) as TControl);
            end;
      end;
    end;
      

  4.   

    请参考:http://www.csdn.net/expert/topic/398/399000.shtm
      

  5.   

    我怀疑是不是和系统的冲突,用
    c_DataStru._Label
    c_DataStru._dxEdit
    试试
      

  6.   

    unit c_DataStru;interfaceuses
      Classes, controls, dxEdLib, stdCtrls;type
      TControltype = (_Label,_dxEdit,_dxCheckEdit);//自定义
      TMySubItem =Class
        Private
          m_value: variant;
          m_name : TComponentName;
          m_Control: TControl;
          m_type  : TControltype;    Public
          Constructor  Create(f_name:string; f_type:Byte; _owner:TComponent; _parent:TWinControl);
          DeStructor  Destroy();
          Procedure    SetParent( _parent:TWinControl);
    end;
    implementation
    {
    Const
            _Label    : Byte =0;
            _dxEdit  : Byte =1;
            _dxCheckEdit : Byte =2;}
    Procedure    TMySubItem.SetParent( _parent:TWinControl);
    begin
      case  m_type of
        _Label    :
            begin
              (m_Control as TLabel).Parent:=_parent;
            end;
        _dxEdit  :
            begin
              (m_Control as TdxEdit).Parent:=_parent;
            end;
        _dxCheckEdit :
            begin
              (m_Control as TdxCheckEdit).Parent:=_parent;
            end;
      end;
    end;Constructor  TMySubItem.Create(f_name:string; f_type:byte; _owner:TComponent);
    //构造时f_type定成byte m_type:=f_type 报错
    //构造时f_type定成Tcontroltype m_type:=f_type 还是报错
    begin
      inherited Create();
      m_type:= f_type;
      m_Control.Parent:=_parent;  case  m_type  of
        _Label    :
            begin
              m_Control:=(TLabel.Create(_owner) as TControl);
            end;
        _dxEdit  :
            begin
              m_Control:=(TdxEdit.Create(_owner) as TControl);
            end;
        _dxCheckEdit :
            begin
              m_Control:=(TdxCheckEdit.Create(_owner) as TControl);
            end;
      end;
    end;
    为什么错
      

  7.   

    你的问题不是Const的问题
    是重载构造的问题哦
    写类方法的时候上下声明有一致
    具体你看看help就可以了
      

  8.   

    A numeral, declared constant, or other expression that the compiler can evaluate without executing your program. It must be of an ordinal type compatible with selectorExpression. Thus 7, True, 4 + 5 * 3, 'A', and Integer('A') can all be used as caseLists, but variables and most function calls cannot. (A few built-in functions like Hi and Lo can occur in a caseList. See Constant expressions.)
      

  9.   

    //试试
    Constructor  Create(f_name:string; f_type:TControltype ; _owner:TComponent; _parent:TWinControl);Constructor  TMySubItem.Create(f_name:string; f_type:TControltype ; _owner:TComponent; _parent:TWinControl);
      

  10.   

    unit c_DataStru;interfaceuses
      Classes, controls, dxEdLib, stdCtrls;type
      TControltype = (ct_Label,ct_dxEdit,ct_dxCheckEdit);//自定义
      TMySubItem =Class
        Private
          m_value: variant;
          m_name : TComponentName;
          m_Control: TControl;
          m_type  : TControltype;    Public
          Constructor  Create(f_name:string; f_type:TControltype; _owner:TComponent; _parent:TWinControl);
          DeStructor  Destroy();
          Procedure    SetParent( _parent:TWinControl);
    end;implementationProcedure    TMySubItem.SetParent( _parent:TWinControl);
    begin
      case  m_type of
        ct_Label    :
            begin
              (m_Control as TLabel).Parent:=_parent;
            end;
        ct_dxEdit  :
            begin
              (m_Control as TdxEdit).Parent:=_parent;
            end;
        ct_dxCheckEdit :
            begin
              (m_Control as TdxCheckEdit).Parent:=_parent;
            end;
      end;
    end;Constructor  TMySubItem.Create(f_name:string; f_type:TControltype; _owner:TComponent;
    _parent:TWinControl);
    begin
      inherited Create();
      m_type:= f_type;
      m_Control.Parent:=_parent;  case  m_type  of
        ct_Label    :
            begin
              m_Control:=(TLabel.Create(_owner) as TControl);
            end;
        ct_dxEdit  :
            begin
              m_Control:=(TdxEdit.Create(_owner) as TControl);
            end;
        ct_dxCheckEdit :
            begin
              m_Control:=(TdxCheckEdit.Create(_owner) as TControl);
            end;
      end;
    end;
     
      

  11.   

    我已看到了,谢谢,最后我想问一下,那里有delphi比较好的参考手册可下(电子版)
    zswang(伴水)(伤心中),谢谢,我肯定加分给你
      

  12.   

    回复人: tikkypeng(千两狂死郎) (2001-8-28 21:37:31)  得20分 
    http://cn.ilike.lycosasia.com/program/book/index.html这里有很多~~  
      

  13.   

    回复人: tikkypeng(千两狂死郎) (2001-8-28 21:41:14)  得0分 
    http://pcbook.godcn.net/download/default.asp?typeid=15这里也有不少~~