你可以使用DesignIntf.RegisterSelectionEditor方法註冊一個選擇編輯器(具體用法請看Delphi原始碼中關於ISelectionEditor的注釋), 然後在RequiresUnits方法根據你的使用方式添加額外的單元引用。
TMySelectionEditor = class(TSelectionEditor)public procedure RequiresUnits(Proc: TGetStrProc); override;end;procedure Register;implementationprocedure TMySelectionEditor.RequiresUnits(Proc: TGetStrProc);var comp: TMyComponent; I: Integer;begin inherited RequiresUnits(Proc); Proc('ExtraUnit'); // might be a better way of doing the code from here onwards? if (Designer=nil)or(Designer.Root=nil) then Exit; for I := 0 to Designer.Root.ComponentCount - 1 do begin if (Designer.Root.Components[i] is TMyComponent) then begin comp := TMyComponent(Designer.Root.Components[i]); if comp.SampleProperty = True then Proc('ExtraUnit2'); Proc(comp.ObjProperty.UnitName); end; end;end;procedure Register;begin RegisterSelectionEditor(TMyComponent, TMySelectionEditor);end;