I'm working on some components in XE2. Is it possible to have more than the component's unit added to the uses clause of the form it's dropped on?
Example: When I choose the TCustomComponent from a package I've built and installed the unit CustomComponent is added to the form's uses clause. I would like to also add the unit GlobalConstants.
Does anyone know if this can be done?
Create a design-time package for your component (if you do not already have one). In that package, create a class that implements the ISelectionEditor
interface (the easiest way is to derive from the TSelectionEditor
class), overriding its virtual RequiresUnits()
method to report any additional units you want to appear in the uses
clause of any Form/Frame/DataModule that uses your component. Then, have your package's Register()
function register that class by calling RegisterSelectionEditor()
(in addition to RegisterComponents()
).
Indy 10 does exactly this for its TIdTCPServer
, TIdCmdTCPClient
, and TIdUDPServer
components, to make sure the IdContext
and IdSocketHandle
units get added to uses
clauses. Look at the IdCoreSelectionEditors.pas
and IdRegisterCore.pas
units to see how Indy implements this.
Update: the IdCoreSelectionEditors.pas
and IdProtocolsSelectionEditors.pas
units were removed from Indy 10 in March 2014. All of the per-component SelectionEditor classes were replaced with a new single class implemented in the IdRegisterCore
unit itself. This new SelectionEditor class is registered for all Indy components, and it looks for all instances of any Indy component that has been placed at design-time, using RTTI of the data types of all parameters and return values for any assigned event handlers to know which units to report for inclusion in the uses
clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With