I discovered my answer a while after asking this question
Since it's not advised to create multiple instances of TIdHTTPWebBrokerBridge
, you don't necessarily need to worry about the existence of multiple different instances of TMyComponent
. You do however need to perform your own checking to make sure multiple instances don't exist in the first place. But since you only have one instance of this Component, you can feel safe declaring a global variable in your component's unit and exposing it to your web module.
Don't just declare a global var
variable directly in the interface
of your unit. Instead, you should protect this...
function MyComponent: TMyComponent;
implementation
uses
MyWebModule;
var
_MyComponent: TMyComponent;
function MyComponent: TMyComponent;
begin
Result:= _MyComponent;
end;
constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited;
_MyComponent:= Self;
end;
destructor TMyComponent.Destroy;
begin
_MyComponent:= nil;
inherited;
end;
initialization
_MyComponent:= nil;
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass:= WebModuleClass;
end.