AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Die Delphi-IDE Komponente vor dem Platzieren umbenennen / OpenTools API
Thema durchsuchen
Ansicht
Themen-Optionen

Komponente vor dem Platzieren umbenennen / OpenTools API

Ein Thema von CG2003 · begonnen am 20. Sep 2006 · letzter Beitrag vom 26. Sep 2006
Antwort Antwort
Seite 1 von 3  1 23      
CG2003

Registriert seit: 8. Nov 2003
Ort: Hamburg
470 Beiträge
 
Delphi 2009 Professional
 
#1

Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 20. Sep 2006, 16:46
Hallo liebe DP,

ich versuche mich gerade an einem kleinen IDE-Experten, mit dem ich Komponenten umbenennen kann, während ich sie auf die Form ziehe. Sowas gibt es ja schon: CNA - Component Naming Assistant,
aber ich will mein eigenes schreiben!

Dazu habe ich folgenden Code im Internet gefunden:

Delphi-Quellcode:
unit ComponentPrefixExpert;

interface

procedure Register;

implementation

uses Windows, SysUtils, Controls, Classes, ToolsAPI, Dialogs;

type
  TPPWIdeNotifier = 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;

  TPPWFormNotifier = 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;

  TPPWModuleNotifier = 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;

procedure Register;
begin
  Index := (BorlandIDEServices as IOTAServices).AddNotifier(TPPWIdeNotifier.Create);
end;


{ TPPWIdeNotifier } 

procedure TPPWIdeNotifier.AfterCompile(Succeeded: Boolean);
begin
end;

procedure TPPWIdeNotifier.BeforeCompile(const Project: IOTAProject;
  var Cancel: Boolean);
begin
end;

constructor TPPWIdeNotifier.Create;
begin
  Inherited Create;
  ShowMessage ('TPPWIdeNotifier created');
end;

destructor TPPWIdeNotifier.Destroy;
begin
  ShowMessage (' Destroying TPPWIdeNotifier ');
  ShowMessage (' Notifiers Left : ' + inttostr(NotifierList.Count));
  inherited Destroy;
end;

procedure TPPWIdeNotifier.FileNotification(
  NotifyCode: TOTAFileNotification; const FileName: string;
  var Cancel: Boolean);
var
  Module : IOTAModule;
  Editor : IOTAEditor;
  FormEditor : IOTAFormEditor;
  ModuleNotifier : TPPWModuleNotifier;
  FormNotifier : TPPWFormNotifier;

  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 := TPPWFormNotifier.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 := TPPWModuleNotifier.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 TPPWFormNotifier.ComponentRenamed(ComponentHandle: TOTAHandle;
  const OldName, NewName: string);
var
  Module : IOTAModule;
  Editor : IOTAEditor;
  FormEditor : IOTAFormEditor;
  OTAComponent: IOTAComponent;
  Component: IComponent;
  I: Integer;
  
begin
  if not FRenaming then
  try
    FRenaming := True;
    Module := ( BorlandIDEServices as IOTAModuleServices ).FindModule(FFileName);
    for i := 0 to Module.GetModuleFileCount - 1 do
    begin
      Editor := Module.GetModuleFileEditor(i);
      if Editor.QueryInterface( IOTAFormEditor, FormEditor ) = S_OK then
      begin
        OTAComponent := FormEditor.FindComponent(OldName);
        if OTAComponent = nil then ShowMessage('OTAComponent not found.')
                              else
        begin
          Component := OTAComponent.GetIComponent;
          if Component = nil then ShowMessage('IComponent not found')
                             else Component.Name := 'Test' + NewName;
        end;
      end
    end;
  finally
    FRenaming := False;
  end;
end;
constructor TPPWFormNotifier.Create( FileName : String );
begin
  inherited Create;
  FFileName := FileName;
  ShowMessage ('Form Notifier Created for File : ' + FileName );
end;

destructor TPPWFormNotifier.destroy;
begin
  ShowMessage ('Form Notifier Destroyed for File : ' + FFileName );
  inherited Destroy;
end;

procedure TPPWFormNotifier.FormActivated;
begin
{} 
end;

procedure TPPWFormNotifier.FormSaving;
begin
{} 
end;

{ TPPWModuleNotifier } 

function TPPWModuleNotifier.CheckOverwrite: Boolean;
begin
  Result := True;
end;

constructor TPPWModuleNotifier.Create(const FileName: String);
begin
  inherited Create;
  FOldFileName := FileName;
  FFileName := FileName;
  ShowMessage ('Module Notifier Created for file : ' + FOldFileName);
end;

destructor TPPWModuleNotifier.destroy;
begin
  ShowMessage ('Module Notifier Destroyed for file : ' + FFileName);
  inherited;
end;

procedure TPPWModuleNotifier.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.
Das Problem ist nur, das er weder "FRenaming" noch "IComponent" findet/kennt.
Oder gibt es eine einfachere Variante eine Art "on the fly Komponenten-Umbenenner" zu entwickeln?

Bin für jeden Hinweis/Tip dankbar!
Sebastian M.
Viele Grüße aus Hamburg


Meine Website: www.sebastian-mundt.com
  Mit Zitat antworten Zitat
CG2003

Registriert seit: 8. Nov 2003
Ort: Hamburg
470 Beiträge
 
Delphi 2009 Professional
 
#2

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 21. Sep 2006, 10:38
*push*
Sebastian M.
Viele Grüße aus Hamburg


Meine Website: www.sebastian-mundt.com
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#3

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 21. Sep 2006, 10:41
Wird ja auch von anderen Extensions gemacht, da diese teilweise OS sind (JVCL, CnExperts ) kannst du dir ja mal die Quellcodes anschauen.
Markus Kinzler
  Mit Zitat antworten Zitat
CG2003

Registriert seit: 8. Nov 2003
Ort: Hamburg
470 Beiträge
 
Delphi 2009 Professional
 
#4

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 21. Sep 2006, 10:48
Zitat von mkinzler:
Wird ja auch von anderen Extensions gemacht, da diese teilweise OS sind (JVCL, CnExperts ) kannst du dir ja mal die Quellcodes anschauen.
ja, ich weiß, doch das Problem ist, das diese viel zu unübersichtlich und viel zu sehr ineinander verstrickt sind, so dass ich da ehrlich gesagt die o.g. gesuchte Funktionalität leider nicht nachvollziehen kann.
Sebastian M.
Viele Grüße aus Hamburg


Meine Website: www.sebastian-mundt.com
  Mit Zitat antworten Zitat
CG2003

Registriert seit: 8. Nov 2003
Ort: Hamburg
470 Beiträge
 
Delphi 2009 Professional
 
#5

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 21. Sep 2006, 12:24
So, habe jetzt meinen FormNotifier soweit geändert, das er erkennt, das eine Komponente umbenannt wird/werden soll, bzw. er erkennt auch, das eine Komponente auf das Formular gezogen wird.

Mit dem Aufruf

SetPropValue(Instance, 'Caption', 'Test'); will ich nun das Property "Name", also die Komponentenbezeichnung in "Test" ändern.
Er durchläuft zwar diesen Aufruf und führt Ihn aus, jedoch wird der Name nicht geändert.


Hier nochmal der FormNotifier:


Delphi-Quellcode:
procedure TPPWFormNotifier.ComponentRenamed(ComponentHandle: TOTAHandle;
  const OldName, NewName: string);
var
  Module : IOTAModule;
  Editor : IOTAEditor;
  FormEditor : IOTAFormEditor;
  OTAComponent: IOTAComponent;
  Component: IOTAComponent;
  I: Integer;
  Instance : TComponent;
  C1, C2: TPersistentClass;
  Match: Boolean;
  begin
  if not FRenaming then
  try
    FRenaming := True;
    Module := ( BorlandIDEServices as IOTAModuleServices ).FindModule(FFileName);
        ShowMessage('Module FindModule OK');
    Instance := TComponent(ComponentHandle);
            ShowMessage('Instance = ComponentHandle');
  if not Assigned(ComponentHandle) then begin
    ShowMessage('ComponentHandle not assignes!');
    Exit;
      end;
  Instance := TComponent(ComponentHandle);
  begin
        SetPropValue(Instance, 'Name', 'Test');
        ShowMessage('SetPropValue OK');
// end;
        end;
// end
  finally
    FRenaming := False;
  end;
end;
Hoffe, es kann mir einer helfen!
Sebastian M.
Viele Grüße aus Hamburg


Meine Website: www.sebastian-mundt.com
  Mit Zitat antworten Zitat
CG2003

Registriert seit: 8. Nov 2003
Ort: Hamburg
470 Beiträge
 
Delphi 2009 Professional
 
#6

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 22. Sep 2006, 11:53
~push~
Sebastian M.
Viele Grüße aus Hamburg


Meine Website: www.sebastian-mundt.com
  Mit Zitat antworten Zitat
Benutzerbild von chaosben
chaosben

Registriert seit: 27. Apr 2005
Ort: Görlitz
1.358 Beiträge
 
Delphi XE2 Professional
 
#7

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 22. Sep 2006, 12:02
Irgendwie hab ich Lust einfach nur "ooooooch" drunter zu schreiben.

Aber was solls: Wir erreichen das von dir gewünschte mit der Prozedur "SetPropByName(...)".
Benjamin Schwarze
If I have seen further it is by standing on the shoulders of Giants. (Isaac Newton)
  Mit Zitat antworten Zitat
CG2003

Registriert seit: 8. Nov 2003
Ort: Hamburg
470 Beiträge
 
Delphi 2009 Professional
 
#8

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 22. Sep 2006, 12:33
Zitat von chaosben:
Irgendwie hab ich Lust einfach nur "ooooooch" drunter zu schreiben.

Aber was solls: Wir erreichen das von dir gewünschte mit der Prozedur "SetPropByName(...)".
Danke.
Aber hättest Du vielleicht ein kleines Codebeispiel für mich?
Ich weiß ja noch nicht einmal, ob der Notifier so richtig definiert ist und vielleicht nur durch Zufall funktioniert?!
Sebastian M.
Viele Grüße aus Hamburg


Meine Website: www.sebastian-mundt.com
  Mit Zitat antworten Zitat
Benutzerbild von chaosben
chaosben

Registriert seit: 27. Apr 2005
Ort: Görlitz
1.358 Beiträge
 
Delphi XE2 Professional
 
#9

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 22. Sep 2006, 12:38
also ein Beispiel:

Delphi-Quellcode:
var
  Compo : IOTAComponent
begin
  Compo:=Editor.FindComponent(OldName); //Editor ist der IOTAFormEditor
  Compo.SetPropByName('Name','NewName');
end;
Benjamin Schwarze
If I have seen further it is by standing on the shoulders of Giants. (Isaac Newton)
  Mit Zitat antworten Zitat
CG2003

Registriert seit: 8. Nov 2003
Ort: Hamburg
470 Beiträge
 
Delphi 2009 Professional
 
#10

Re: Komponente vor dem Platzieren umbenennen / OpenTools API

  Alt 22. Sep 2006, 12:50
Erstmal danke für Dein Beispiel. Mein Aufruf für "ComponentRenamed" sieht jetzt so aus:

Delphi-Quellcode:
procedure TPPWFormNotifier.ComponentRenamed(ComponentHandle: TOTAHandle;
  const OldName, NewName: string);
var
  Module : IOTAModule;
  Editor : IOTAEditor;
  FormEditor : IOTAFormEditor;
  Compo: IOTAComponent;
  I: Integer;

begin
  if not FRenaming then
  try
    FRenaming := True;
    Module := ( BorlandIDEServices as IOTAModuleServices ).FindModule(FFileName);
    for i := 0 to Module.GetModuleFileCount - 1 do
    begin
      Editor := Module.GetModuleFileEditor(i);
      if Editor.QueryInterface( IOTAFormEditor, FormEditor ) = S_OK then begin
        Compo := FormEditor.FindComponent(OldName);
        Compo.SetPropByName('Name','Testname');
      end
    end;
  finally
    FRenaming := False;
  end;
end;
Wenn ich das Ganze jetzt aber als Package installieren, und eine Komponente aufs Formular ziehe, bekomme ich eine Zugriffsverletzung.

Habe ich vielleicht was falsch gemacht?
Sebastian M.
Viele Grüße aus Hamburg


Meine Website: www.sebastian-mundt.com
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz