type
       TGroup=class(TcollectionItem)
   private
    FGroupID: string;
    FGroupName: string;
    FMajorGrade: TMajorGrade;
   public
      property GroupID:string ;
      property GroupName:string ;
      property MajorGrade:TMajorGrade ;      
end;
var thegroup:Tgroup;
在程序中我要给对象成员Majorgrade的majorgradeid属性付值,应该怎么办,是否要
首先初始化majorgrade?  如何初始化。

解决方案 »

  1.   

    在TGroup 中重载constuctor函数,对变量赋值
      

  2.   

    TGroup=class(TcollectionItem)
     public                     { constructors are always public }
        constructor Create(AOwner: TComponent); override; { this syntax is always the same }
      end;
    ...
    constructor TGroup.Create(AOwner: TComponent);     { this goes after implementation }
    begin
      inherited Create(AOwner);                           { ALWAYS do this first! }
      FMajorGrade:=;//这里进行操作end;