Board index » delphi » Delphi 7 and De{*word*81}Services notifier causing error on close.

Delphi 7 and De{*word*81}Services notifier causing error on close.


2006-07-30 05:03:48 AM
delphi241
Hi,
I'm trying to get an ide plugin working at runtime. I have got my plugin
working after a fashion, can do what I want to do (which is write out an
evaluated variable to a file rather than screen) but I have one serious
problem. Attaching a notifier to the IOTADe{*word*81}Services appears to cause
a access violation on exiting the IDE. The rest works fine.
To track this down I started again and created a plugin (wizard/expert)
that does nothing but implement IOTADe{*word*81}Notifier and call this in the
register method.
(BorlandIDEServices as
IOTADe{*word*81}Services ).AddNotifier(TTobyDe{*word*81}Notifier.create);
Everything is fine until you close the IDE and you get several access
violations.
Does anyone know anything about this? Is it just my machine? I am using
Delphi 7 Build 4.453
Thanks
Toby Allen.
 
 

Re:Delphi 7 and De{*word*81}Services notifier causing error on close.

Toby Allen writes:
Quote
(BorlandIDEServices as
IOTADe{*word*81}Services ).AddNotifier(TTobyDe{*word*81}Notifier.create);
Everything is fine until you close the IDE and you get several access
violations.
Do you also remove the notifier before your addin unloads?
Erik
 

Re:Delphi 7 and De{*word*81}Services notifier causing error on close.

No.
I couldnt see where to do this. What section should I remove the notifier.
Is there a certain event, a finalization section? I couldnt figure out what
is called when the addin is unloaded.
Thanks
Toby Allen.
"Erik Berry" <XXXX@XXXXX.COM>writes
Quote
Toby Allen writes:
>(BorlandIDEServices as
>IOTADe{*word*81}Services ).AddNotifier(TTobyDe{*word*81}Notifier.create);
>Everything is fine until you close the IDE and you get several access
>violations.

Do you also remove the notifier before your addin unloads?

Erik
 

Re:Delphi 7 and De{*word*81}Services notifier causing error on close.

Simply create your notifer in the constructor of your Addin and then free it in the destructor of
your addin.
example:
TBeforeCompile = class(TIExpert)
private
{ Private declarations }
fNotifier: TNotifier;
..
..
TNotifier = class(TIAddInNotifier)
private
fOwner: TBeforeCompile;
public
constructor Create(Owner: TBeforeCompile);
..
..
constructor TNotifier.Create(Owner: TBeforeCompile);
begin
inherited Create;
fOwner := Owner;
if not ToolServices.AddNotifierEx(Self) then
raise Exception.Create('Cannot add notifier');
end;
destructor TNotifier.Destroy;
begin
ToolServices.RemoveNotifier(Self);
inherited Destroy;
end;
constructor TBeforeCompile.Create;
begin
inherited Create;
fNotifier := TNotifier.create(Self);
end;
destructor TBeforeCompile.Destroy;
begin
fNotifier.free;
inherited Destroy;
end;
Dennis Passmore
"If you cannot conceive the idea you
will never achieve the desired results"
 

Re:Delphi 7 and De{*word*81}Services notifier causing error on close.

Toby Allen writes:
Quote
I couldnt see where to do this. What section should I remove the notifier.
Is there a certain event, a finalization section? I couldnt figure out what
is called when the addin is unloaded.
You need to remove your notifier whenever you no longer need the
notifications. This could happen at any number of times, such as when your
package/dll unloads using a finalization section, maybe when the user
changes something from your options dialog to turn off the feature, when
the current project closes if you don't care about all projects, when your
addin is unloaded using IOTAWizard.Destroyed, etc.
The same rule applies to almost all of the notifiers in the OTA - if you
add one, you are also in charge of removing it at some point.
Erik