我想在組件無法加載時向組件添加條件狀態,並通知其用戶(開發人員)此組件無法在設計時加載,並且在運行時(目標用戶可能安全)在運行時無法加載。如何在構造函數中加載組件加載?
如何防止組件在其構造函數中加載以及如何在設計時和運行時安全地從構造函數中顯示消息(異常)?
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;
謝謝
您的測試是在構造函數中(而不是在Loaded方法中),因爲在從DFM開始載入屬性之前需要消息,是否正確? – mjn 2011-12-22 06:28:54