相关疑难解决方法(0)

如何使用2个或更多类实现相同的方法?

我想写一个TCheckBoxTRadioButton后代有3个相同的方法.

TMyCheckBox = class(TCheckBox)
  procedure DoSomething1;
  procedure DoSomething2;
  procedure WMSize(var Message: TWMSize); message WM_SIZE;
end;

TMyRadioButton = class(TRadioButton)
  procedure DoSomething1;
  procedure DoSomething2;
  procedure WMSize(var Message: TWMSize); message WM_SIZE;
end;

// the following procedures are common for both classes, so in fact
// TMyCheckBox.DoSomething1 do the same as TMyRadioButton.DoSomething1

procedure DoSomething1;
begin
  // here is the same code for TMyCheckBox as well as for TMyRadioButton
  // but I don't want to write the same code many times …
Run Code Online (Sandbox Code Playgroud)

delphi delphi-7

6
推荐指数
2
解决办法
439
查看次数

标签 统计

delphi ×1

delphi-7 ×1