Changing component class at run-time on demand

后端 未结 3 2041
误落风尘
误落风尘 2020-12-01 07:17

My Question is similar to the idea here: Replacing a component class in delphi.
But I need to change a specific component(s) class on demand.
Here is some p

3条回答
  •  误落风尘
    2020-12-01 07:20

    There's no automatic way to do that, but you could try something like this:

    procedure MakeSuperImageList(var ImageList: TImageList);
    var
      new: TImageList;
    begin
      if ImageList is TSuperImageList then
        Exit;
      new := TSuperImageList.Create(ImageList.Owner);
      new.Assign(ImageList);
      ImageList.Free;
      ImageList := new;
    end;
    

    Depending on how Assign is implemented, it may not quite work as expected, but you can override Assign or AssignTo on TSuperImageList to get the desired behavior.

提交回复
热议问题