相关疑难解决方法(0)

根据需要在运行时更改组件类

我的问题类似于这里的想法:在delphi中替换组件类.
但我需要根据需要更改特定的组件类.
这是一些伪演示代码:

unit Unit1;

TForm1 = class(TForm)
  ImageList1: TImageList;
  ImageList2: TImageList;
private
  ImageList3: TImageList;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ImageList3 := TImageList.Create(Self);
  // all instances of TImageList run as usual
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Unit2.MakeSuperImageList(ImageList2);
  Unit2.MakeSuperImageList(ImageList3);
  // from now on ONLY ImageList2 and ImageList3 are TSuperImageList
  // ImageList1 is unchanged
end;
Run Code Online (Sandbox Code Playgroud)
unit Unit2;

type
  TSuperImageList = class(Controls.TImageList)
  protected
    procedure DoDraw(Index: Integer; Canvas: TCanvas; X, Y: Integer;
      Style: Cardinal; Enabled: Boolean = True); override;
  end; …
Run Code Online (Sandbox Code Playgroud)

delphi vcl delphi-5

16
推荐指数
2
解决办法
3825
查看次数

标签 统计

delphi ×1

delphi-5 ×1

vcl ×1