我有两个组件 A 和 B。组件 B 派生自组件 A,并与它共享大多数属性和过程。现在我有一个像这样的冗长程序:
procedure DoSomething;
begin
Form1.Caption := Component_A.Caption;
// hundreds of additional lines of code calling component A
end;
根据组件 B 是否处于活动状态,我想重用上述过程并将 Component_A 部分替换为组件 B 的名称。它应该如下所示:
procedure DoSomething;
var
C: TheComponentThatIsActive;
begin
if Component_A.Active then
C := Component_A;
if Component_B.Active then
C := Component_B;
Form1.Caption := C.Caption;
end;
在Delphi2007中我怎么能做到这一点?
谢谢!