Delphi 動態創建控件,賦值,使用



uses

中定義:

type
  TMyComponent = class(TComponent)
  public
    item1, item2, item3, item4, item5, item6: string;
    constructor Create(Owner1: TComponent; s1: string); overload;
    constructor Create(Owner1: TComponent; s1, s2, s3: string); overload;
    constructor Create(Owner1: TComponent; s1, s2, s3, s4, s5, s6: string); overload;
  end;

定義過程:

{ TMyComponent }

constructor TMyComponent.Create(Owner1: TComponent; s1: string);
begin
  inherited Create(Owner1);
  item1 := s1;
  item2 := item1;
  item3 := item1;
  item4 := item1;
  item5 := item1;
  item6 := item1;
end;


創建控件:

 ComboBoxLine.Items.AddObject(FieldByName('SectionName').AsString, TMyComponent.Create(Self, FieldByName('SectionDetail').AsString));

使用:

 ComboBoxLine.Items.Objects[i] as TMyComponent).item1



你可能感兴趣的:(DELPHI)