Delphi's integrated development environment (IDE) offers a very wide range of tools, commands and options ready to use. However, one day you may find that, of all these features, it happens to be the most dear to you that is missing; alternatively, you could start thinking of an 'automation' and think that if Delphi were able to do it, that would certainly save you a lot of time in your work, avoiding doing everything again and again many times, with the risk of making mistakes. If this range of situations seems very familiar to you but you don't know where to start, this talk is just for you! Thanks to the Open Tools API (OTA), Delphi allows us to interact with the IDE to add new commands, new tool windows, new wizards and project templates. Thanks to an in-depth explanation and several specially designed code examples, we will see together what it takes to extend the functionality of the IDE, to automate it and thus bring it closer to our own way of working.
5. Plugins have made the success of many
apps.
• Browsers
o Mozilla Firefox
o Google Chrome
• CMS
o Wordpress
o Drupal
• Developer tools
o Atom
o Eclipse
o Visual Studio Code
Sometimes, plugins are the piece
of software that really matters.
Plugins, plugins, plugins!
6. Delphi has some really good add-ons or
tools, freeware or opensource.
• General purpose and coding
• GExperts
• ModelMaker Code Explorer (MMX)
• CnPack Wizards
• DDevExtensions
• Documentation Insight
• Castalia
• Error handling
• Eureka Log
• madExcept
• Testing and quality
• Automated QA
• Test Insight
• Hot fixes
• Delphi SpeedUp
• IDE Fix Pack
…and many others… 👌
But Delphi often lacks specific, targeted
and «feature focused» plugin. 🤔
What about Delphi?
7. What do I mean?
Open Command
Line
Add New File Trailing Whitespace
Visualizer
Dummy Text
Generator
Show Selection
Length
XML, XPath
& XSLT Tools
Comment
Remover
Console Launcher
Solution Cleaner PowerShell Prompt Encourage Farticus
8. The only limit is the sky!
Many scenarios deals with writing code, but this is not always the case.
You can create
• Productivity tools that add file templates and projects, refactoring and
cleaning code, add new dialogs or tool windows.
• Support for new syntax and languages directly in the editor.
• Domain specific designers that allow you to «draw» a model and optionally
produce the code (or not).
• Extend debugging features
• Create replacements, integrations and work arounds of limited or disliked IDE
features
What can I do?
9. • Do things faster!
• Invest more time in automation than documentation
• More speed, less errors, high reliability, soft learning curve
• Share your tools with colleagues or an entire community to get
feedback and improvements, and also new tools
• Decorate your framework with templates for projects and modules
• Fix Delphi bugs or implement workarounds waiting for fixes
• Last but not least… have fun!
Benefits
12. • Suite of over 100 interfaces!
• Let’s you interact with and control the IDE
Main action lists, image lists and menus
Tool bars
Modules and source editors
Keyboard macros and bindings
Forms (and their components)
Debugger and Breakpoints
Code Completion
Message View
To-Do List
Build process
Project and Item Repository
What is Tools API
13. • All the interfaces are inside a unique code file:
C:Program Files (x86)EmbarcaderoStudio20.0sourceToolsAPI.pas
• You can implement some interfaces to extend the IDE
• ToolsAPI provides some main kinds of extensions
• Wizard
a sort of setup class to easily build simple features (or host complex ones)
• Notifier
a class that contains logic that Delphi calls back when something interesting happens
• Creator
a class that supports the creation of new project, modules, units or virtually any kind of file
How to use ToolsAPI
14. interface
uses
ToolsAPI;
type
TFirstWizard = class(TInterfacedObject, IOTAWizard)
public
procedure Execute;
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure AfterSave;
procedure BeforeSave;
procedure Destroyed;
procedure Modified;
end;
Sample Wizard
15. Where to put the code
Package
(.dpk)
Library
(.dll)
16. Library (.dll)
Library
(.dll)
• Quite «old school» solution
• They must be installed via registry
• Runtime packages are required!
• Registration, initialization and
finalization code is more complex
o You have to set the Application
variable
o What about the Memory Manager?
• Delphi loads them early (some
menus to anchor to may not be
available)
17. • Natural container for all the
elements in Delphi (types,
records, classes, interfaces,
routines, forms, frames, data
modules, …)
• Use of runtime packages is
embedded
• Register classes (and hence
experts) is easy and
straightforward
• They can be installed/uninstalled
«hot» and «live» directly from
the IDE
Where to put the code
Package
(.dpk)
19. • There is little… no documentation 😢
• You should refer to the comments inside «ToolsAPI.pas»
• Pay attention! Your code runs inside the IDE
• Delphi can crash or hang if your code misbehave or has errors
• Testing is difficult, debugging even more!
• If you are unsure, install the tool using a separate profile
• Launch the Delphi IDE (bds.exe) as the Host Application
• An effective «Code DOM» and a working parser would be appreciated
• We hope that LSP support will resolve this issue and fill the gap
Warning!
21. NTA (Native Tools API)
• Grants direct access to actual IDE
objects, such as the TMainMenu
object of the IDE.
• The wizard must use RAD Studio
packages (rtl, vcl, …).
• The wizard is tied to a specific
version of the IDE.
Native/Open Interfaces
OTA (Open Tools API)
• Interfaces do not grant full access
to the IDE.
• All the functionality is available
through OTA interfaces.
• Interacting and extending the IDE
occurs with the OTA layer as a
mediator.
22. • Services give access to specific features through interfaces.
• Interfaces can be obtained from one single global variable:
BorlandIDEServices.
• To get a service reference, you can call the Supports() method
or cast BorlandIDEServices to the required type.
• Some interfaces have numbers (are versioned when changed).
Tools API Services
24. var
LServices: IOTAWizardServices;
begin
LServices := BorlandIDEServices as IOTAWizardServices;
WizardIndex := LServices.AddWizard(TFirstWizard.Create);
end;
begin
with BorlandIDEServices as IOTAWizardServices do
WizardIndex := AddWizard(TFirstWizard.Create);
end;
Get a service /2
Presentarsi molto velocemente per procedere poi con il tema principale.
Spiegare subito qual è il tema della sessione.
Nel talk si parlerà di creare plugin (con tutti i relativi sinonimi) per arricchire le funzionalità di Delphi. Anticipare poi la motivazione per cui si ritiene questo tema estremamente importante.
Evidenziare come, per molti software (compreso i concorrenti di Delphi) la presenza di un fiorente marketplace di plugin disponibili aumenti l’adozione dell’ambiente di sviluppo e crei un maggiore senso di community, fino ad arrivare al caso estremo di «VSCode» dove i plugin costituiscono la parte più rilevante del software.
Illustrare la situazione nel mondo Delphi, prevalentemente costituita da prodotti «macro», che spesso estendono l’IDE per gestire le proprie funzionalità, o nel caso di feature specifiche sono «collezioni» che a volte si sovrappongono pure e finiscono anche per ostacolarsi. Chiarire quindi qual è il tipo di estensione che si ha in mente.
Fornire qualche esempio di plugin che sarebbe interessante avere in Delphi e che risolve problematiche molto specifiche, ma nel contempo accelerando i tempi di sviluppo e riducendo drasticamente il «time to marker», con l’unico limite della fantasia. Mostrare anche il demo del plugin «Code Smells».
Spiegare quali sono i tipi di estensione che si possono creare e le funzionalità che possono avere (magari qualcuno non ci ha mai pensato).
Cosa fare quindi? Introdurre il percorso esplorativo per la creazione di nuovi expert per Delphi, esortando il pubblico a farlo e, se si ottiene qualcosa di utile, condividerlo, magari proponendo uno spazio su GetIt o DCI o altrove per beneficiarne tutti.
Creazione package, agg. riferimento a «DesignIDE», creazione classe OTAWizard.
Fare carrellata di tutti i demo che è stato possibile produrre.