如何在构造函数中中断组件?

Mar*_*ner 1 delphi constructor components delphi-2009

我想在组件无法加载时向条件状态添加条件状态,并告知其用户(开发人员)该组件无法在设计时加载并在运行时以目标用户加载(如果可能的话,安全地以某种方式安全).

如何防止组件在其构造函数中加载以及如何在设计时和运行时安全地显示构造函数中的消息(异常)?

constructor TSomeComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  if csDesigning in ComponentState then
    if SomeIncompatibleCondition then
      begin
        // how to display message (exception) about the wrong 
        // condition and interrupt the loading of the component ?
      end;

  // is it possible to do the same at runtime ?
end;
Run Code Online (Sandbox Code Playgroud)

谢谢

Rem*_*eau 6

提出异常,例如:

constructor TSomeComponent.Create(AOwner: TComponent); 
begin 
  inherited Create(AOwner); 
  if SomeIncompatibleCondition then 
    raise Exception.Create('Incompatible condition detected!');
end; 
Run Code Online (Sandbox Code Playgroud)