Replacing a component class in delphi

前端 未结 2 1820
时光说笑
时光说笑 2020-11-29 02:15

I know I\'ve seen an example somewhere of a hack to define a custom version of an existing VCL component, like TButton or TEdit, with the same class name and do something to

2条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 02:37

    I guess what you're trying to remember is an "interposer class": inheriting a class giving the same name as the ancestor, by prefixing the ancestor's unit name. Since the class name is not changed, the dfm streaming mechanism is not disturbed. Would only affect the unit the class is re-declared in, unless it is put in a separate unit and that unit is included in the uses section after the base class'es. Obviously, you cannot have published properties in an interposed class.

    type
      TButton = class(stdctrls.TButton)
      protected
        procedure CreateParams(var Params: TCreateParams); override;
      end;
    
      TForm1 = class(TForm)
        Button1: TButton;
        [...]
      private
    

提交回复
热议问题