 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Maziar Navahan Guest
|
Posted: Sat Dec 23, 2006 9:12 am Post subject: why i dont true remve notifires ? |
|
|
i use below code for notify component rename but some times see the when
destroy the some notifier don free
(i see message of if NotifierList.Count > 0 then
ShowMessage (' Notifiers Left : ' + inttostr(NotifierList.Count));
)
what is wrong and how reolve it ?
the actual code :
unit uUserRightExpert;
interface
uses Windows, SysUtils, Controls, Classes, ToolsAPI, Dialogs, DesignIntf;
procedure ExpertRegisterations;
type
TURIDENotifier = class( TNotifierObject, IOTANotifier, IOTAIDENotifier)
public
constructor Create;
destructor Destroy; override;
{ IOTAIDENotifier }
procedure FileNotification(NotifyCode: TOTAFileNotification;
const FileName: string; var Cancel: Boolean);
procedure BeforeCompile(const Project: IOTAProject; var Cancel:
Boolean); overload;
procedure AfterCompile(Succeeded: Boolean); //overload;
end;
TURFormNotifier = class( TNotifierObject, IOTANotifier, IOTAFormNotifier )
private
FFileName : String;
public
constructor Create( FileName : String );
destructor Destroy; override;
procedure FormActivated;
procedure FormSaving;
procedure ComponentRenamed(ComponentHandle: TOTAHandle;
const OldName, NewName: string);
{ IOTAModuleNotifier }
end;
TURModuleNotifier = class( TNotifierObject, IOTANotifier,
IOTAModuleNotifier )
private
FOldFileName : String;
FFileName : String;
public
constructor Create (Const FileName : String);
destructor destroy; override;
{ IOTAModuleNotifier }
function CheckOverwrite : Boolean;
procedure ModuleRenamed(const NewName: string);
end;
var
Index : Integer;
NotifierList : TStringList;
implementation
procedure ExpertRegisterations;
begin
Index := (BorlandIDEServices as
IOTAServices).AddNotifier(TURIDENotifier.Create);
end;
{ TPPWIdeNotifier }
procedure TURIDENotifier.AfterCompile(Succeeded: Boolean);
begin
end;
procedure TURIDENotifier.BeforeCompile(const Project: IOTAProject;
var Cancel: Boolean);
begin
end;
constructor TURIDENotifier.Create;
begin
Inherited Create;
end;
destructor TURIDENotifier.Destroy;
var
i: Integer;
FormNotifierI: Integer;
begin
if NotifierList.Count > 0 then
ShowMessage (' Notifiers Left : ' + inttostr(NotifierList.Count));
inherited Destroy;
end;
procedure TURIDENotifier.FileNotification(
NotifyCode: TOTAFileNotification; const FileName: string;
var Cancel: Boolean);
var
Module : IOTAModule;
Editor : IOTAEditor;
FormEditor : IOTAFormEditor;
ModuleNotifier : TURModuleNotifier;
FormNotifier : TURFormNotifier;
IModuleNotifier : Integer;
FormNotifierI, ListI, I : Integer;
begin
Case NotifyCode of
ofnFileOpened :
begin
{ Get the IOTAModule associated to this File }
Module := ( BorlandIDEServices as
IOTAModuleServices ).FindModule(FileName);
{ Loop over the number of associated File }
for i := 0 to Module.GetModuleFileCount - 1 do
begin
{ Get the FileEditor }
Editor := Module.GetModuleFileEditor(i);
if Editor.QueryInterface( IOTAFormEditor, FormEditor ) = S_OK then
begin
{ If the File Editor is a FormEditor then Add Our Notifier }
FormNotifier := TURFormNotifier.Create( FileName );
FormNotifierI := FormEditor.AddNotifier ( FormNotifier );
if FormNotifierI < 0 then
begin
FormNotifier.Free;
end
else
begin
//ShowMessage( 'Notifier Index' + inttostr( FormNotifierI ));
NotifierList.AddObject(FileName, Pointer(FormNotifierI));
end;
{ Also Add a module Notifier }
ModuleNotifier := TURModuleNotifier.Create( FileName );
IModuleNotifier := Module.AddNotifier( ModuleNotifier );
if IModuleNotifier < 0 then
begin
ModuleNotifier.Free;
end;
end
end;
end;
ofnFileClosing :
begin
if NotifierList.Find(FileName, ListI) then
begin
Module := ( BorlandIDEServices as
IOTAModuleServices ).FindModule(FileName);
FormNotifierI := Integer(NotifierList.Objects[ListI]);
for i := 0 to Module.GetModuleFileCount - 1 do
begin
Editor := Module.GetModuleFileEditor(i);
if Editor.QueryInterface( IOTAFormEditor, FormEditor ) = S_OK then
begin
FormEditor.RemoveNotifier ( FormNotifierI );
NotifierList.Delete(ListI);
end;
end;
end;
end;
end;
end;
{ TPPWFormNotifier }
procedure TURFormNotifier.ComponentRenamed(ComponentHandle: TOTAHandle;
const OldName, NewName: string);
begin
if ((OldName = '') and (NewName = '' ) ) then
beep;
Showmessage( 'Old Name : ' + OldName + chr( 13 ) +
'New Name : ' + NewName );
{ In here I will have to put my
ComponentPrefix Code }
end;
constructor TURFormNotifier.Create( FileName : String );
begin
inherited Create;
FFileName := FileName;
ShowMessage ('Form Notifier Created for File : ' + FileName );
end;
destructor TURFormNotifier.destroy;
begin
showMessage ('Form Notifier Destroyed for File : ' + FFileName );
inherited Destroy;
end;
procedure TURFormNotifier.FormActivated;
begin
{}
end;
procedure TURFormNotifier.FormSaving;
begin
{}
end;
{ TPPWModuleNotifier }
function TURModuleNotifier.CheckOverwrite: Boolean;
begin
Result := True;
end;
constructor TURModuleNotifier.Create(const FileName: String);
begin
inherited Create;
FOldFileName := FileName;
FFileName := FileName;
ShowMessage ('Module Notifier Created for file : ' + FOldFileName);
end;
destructor TURModuleNotifier.destroy;
begin
ShowMessage ('Module Notifier Destroyed for file : ' + FFileName);
inherited;
end;
procedure TURModuleNotifier.ModuleRenamed(const NewName: string);
var
ListI : Integer;
FormNotifierI : Integer;
begin
if NotifierList.Find(FOldFileName, ListI) then
begin
FormNotifierI := Integer(NotifierList.Objects[ListI]);
NotifierList.Delete(ListI);
NotifierList.AddObject(NewName, Pointer(FormNotifierI));
end;
FOldFileName := NewName;
FFileName := NewName;
inherited ;
end;
initialization
NotifierList := TStringList.Create;
NotifierList.Sorted := True;
finalization
(BorlandIDEServices as IOTAServices).RemoveNotifier(Index);
NotifierList.Free;
end. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|