Quiero escribir un TCheckBox
y TRadioButton
descendientes que tienen 3 métodos idénticos.¿Cómo implementar métodos idénticos con 2 y más clases?
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 but implement it
// for both classes at once in some common way
end;
procedure DoSomething2;
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 but implement it
// for both classes at once in some common way
end;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
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 but implement it
// for both classes at once in some common way
end;
¿Cómo puedo hacer esto?
¿Se refiere a declaraciones idénticas (usando la interfaz) o implementaciones idénticas (usando el mismo antecesor)? – Kromster
@Krom, esa es una buena pregunta. Lo que realmente quise decir es implementaciones idénticas. – ZigiZ
El debe mostrarnos la implementación para obtener una respuesta válida. –