Programmable change Component Palette of Delphi IDE
If you often work with Delphi, if Delphi has installed a lot of components and if you always have to use a lot of components in your projects, then you will ever get tired. Are you tired of finding the desired component palette icon on the Component toolbar?
The Component Palette of Delphi IDE is simply a TAB-form control with a single-row header, so it will take you a long time to search when there are too many components. This article is intended to help relieve this "frustration" by setting Multi-lines properties for the TAB Component Palette control with simple tricks that you might not expect. Here I use Delphi 7 but with the lower versions there are not many changes.
Introduction to Delphi IDE
Delphi IDE (Integrated Development Environment) is Delphi's integrated development environment. Depending on the specific version of Delphi, Delphi IDE components also have certain changes. For example, in Delphi 7, the IDE consists of five main components:
1. Delphi main window : The code name of this window is TAppBuilder . This window includes menus, toolbars, and a panel of development tools (Component Palette).
2. FORM design window : This is the actual window for your application program. Start the window as a FORM every time you start Delphi.
3. Object Inspector window : The window name of the window is TPropertyInspector . This is the window that allows you to change the properties for the component on the FORM such as title, name . in an intuitive way.
4. Code Editor code editor window : The code name of the window is TEditWindow . This is the place to actually show the content of the program, where you type the command, design the content for the procedure, give the function and install the methods for the class.
5. Object TreeView Window : The window name of the window is TObjectTreeView . The window will show you a visual way of the parent order of components present on FORM .
Delphi IDE itself is a assembly environment. Delphi opens up for you a lot of approaches to change and edit to fit and facilitate each individual. For example, the Component Palette of Delphi IDE is actually a TTabControl object no more or less. You can see this through a piece of code used to install the TAppBuilder window.
object TabControl: TComponentPaleAppBuildertteTabControl
Left = 0
Top = 0
Width = 64
Height = 47
Align = alClient
Constraints.MinWidth = 20
HotTrack = True
PopupMenu = PaletteMenu
TabOrder = 0
TabStop = False
OnChange = TabControlChange
OnDragDrop = TabControlDragDrop
OnDragOver = TabControlDragOver
OnEndDrag = TabControlEndDrag
OnMouseDown = TabControlMouseDown
OnMouseMove = TabControlMouseMove
OnStartDrag = TabControlStartDrag
BorderStyle = bsNone
OnHelpRequest = ComponentPaletteHelpRequest
object PageScroller1: TPageScroller
Left = 32
Top = 6
Width = 31
Height = 39
Align = alClient
AutoScroll = True
TabOrder = 0
OnScroll = PageScroller1Scroll
end
object Panel2: TPanel
Left = 4
Top = 6
Width = 28
Height = 39
Align = alLeft
BevelOuter = bvNone
TabOrder = 1
SelectorButton object: TSpeedButton
Left = 0
Top = 0
Width = 28
Height = 28
GroupIndex = 1
Down = True
Flat = True
end
end
end
end
Thus, there are two ways to set Multi-lines properties for the TAB Component Palette control. The idea of the first way is to directly change the binary code of delphi32.exe file in the Delphi BIN folder. To do this, please add the property settings of TabControl in the code above on the following command:
MultiLine = True
I tried this way and the results were quite good. However, this way has a slight drawback when your Component Palette is in the Dock state on the Delphi main window, resizing is not possible (see Figure 1).
Figure 1 : Error with how to edit delphi32.exe directly
The idea of the second way is that we will write a small component. Every time Delphi loads this component, it will be tasked to find the Delphi main window, then find the right TAB Component Palette control and directly change the TAB's MultiLine attribute. It looks like a fantasy but as mentioned, Delphi IDE is a professional assembly environment. Delphi IDE itself opens a lot of directions for you to customize. We will step by step understand the code to perform the above tasks.
Find the main window of Delphi
There are many ways to find the main window of Delphi. Note, the component you are about to write is interacting directly with Delphi IDE, so you get the Application window yourself as the Delphi Application window. So, in your own opinion, you can use the following code to find the main window:
function GetIdeMainForm: TCustomForm;
begin
Result: = TForm (Application.FindComponent (AppBuilder));
end;
Find the TAB Component Palette control
To find this TAB control, use the following code:
function GetTabControl: TTabControl;
var
MainForm: TCustomForm;
begin
Result: = nil;
MainForm: = GetIdeMainForm;
if MainForm <> nil then
Result: = TTabControl (MainForm.FindComponent (TabControl))
end;
Find the popup menu of the TAB Component Palette control
To do this, use:
function GetComponentPalettePopupMenu: TPopupMenu;
var
MainForm: TCustomForm;
begin
Result: = nil;
MainForm: = GetIdeMainForm;
if MainForm <> nil then
Result: = TPopupMenu (MainForm.FindComponent (PaletteMenu));
end;
We want to find this popup menu because we will add a Multi-Lines option to switch between the two states of the TAB Component Palette (see Figure 2).
Figure 2 : New selection
The entire content of the component code can be seen in the "Source code" section.
Install and use
To use the newly created component, you need to install into Delphi IDE.
Step 1 . Save the entire contents of the above code into a file, for example I select the file named IdeEnhancement.pas .
Step 2 . Select the Install Component function on the Component menu of Delphi IDE. A new window appears. Please declare the information as shown in Figure 3. Then click OK .
Figure 3 : Set up information for the component
Step 3 . Delphi will ask if you immediately compile this component or not. Please boldly choose "no". Then record what you have just done.
Step 4 . In the IDE's Package window, select the Install function (see Figure 4).
Figure 4 : Component Installation
That's it. Please close the package and then try to right click on the TAB Component Palette. You will be surprised to see the appearance of a new item named Multi-Lines . Click this option and observe the difference. (See Figure 5)
Figure 5. Illustrating the result
If you are a bit more observant, you can easily see that my Delphi IDE is supported by Style XP (when running on Windows XP). To do this, simply create a file named delphi32.exe.manifest with the following content:
Ngo Quoc Anh
language = "*" />
Then save the same folder as the delphi32.exe file (see Figure 6).
Figure 6 : Illustrating XP Style for Delphi IDE
This article is really just a brief introduction to customizing Delphi IDE. Hopefully I will have another opportunity to present better tricks in programming for Delphi IDE.
Source code
IdeEnhancement unit;
interface
dùng
Windows, Messages, SysUtils, Classes, Graphics, Controls, ExtCtrls,
Forms, Dialogs, ComCtrls, Menus, Registry;
type
TMyExpertObject = class (TComponent)
private
App: TCustomForm;
TabControl: TTabControl;
MultiLine: Boolean;
ComponentPalette Menu: TPopupMenu;
// Two items selected for the popup menu that we added
MultiLineItem, SeperatorItem: TMenuItem;
procedure UpdateOtherWindows (OldHeight: Integer);
procedure ResizeMultiLineComponentPalette (Sender: TObject);
function GetIdeMainForm: TCustomForm;
function GetTabControl: TTabControl;
function GetComponentPalettePopupMenu: TPopupMenu;
procedure OnMenuPopup (Sender: TObject);
procedure OnMultiLineItemClick (Sender: TObject);
procedure SetMultiLineComponentPalette (_multiLine: Boolean);
procedure CreateMenuItem (_multiLine: Boolean);
procedure DestroyMenuItem;
procedure SaveSettings;
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
end;
var
MyExpertObject: TMyExpertObject;
implementation
{This is the method that will be called by Delphi every time the component is loaded. Chúng ta cần gọi phương thức này để đọc thuộc tính MultiLines trong Registry} We need to call this method to read MultiLines properties in the Registry}
constructor TMyExpertObject.Create;
begin
inherited;
with TRegistry.Create due
begin
RootKey: = HKEY_CURRENT_USER;
if OpenKey (SoftwareNgo Quoc Anh, False) then
if KeyExists (MultiLines) then
MultiLine: = ReadBool (MultiLines);
end;
end;
{This is the method that will be called by Delphi every time the component frees}
TMyExpertObject.Destroy destructor;
begin
inherited;
end;
{Record information about MultiLines in the Registry every time there is a change}
procedure TMyExpertObject.SaveSettings;
begin
with TRegistry.Create due
begin
RootKey: = HKEY_CURRENT_USER;
if OpenKey (SoftwareNgo Quoc Anh, True) then
WriteBool (MultiLines, MultiLine)
end;
end;
{Recalculate the size of the TAB control every time there is a change}
procedure TMyExpertObject.ResizeMultiLineComponentPalette (Sender: TObject);
var
AHeight: Integer;
begin
với Sender as TTabControl
begin
AHeight: = Height - (DisplayRect.Bottom - DisplayRect.Top) + 29;
Constraints.MinHeight: = AHeight;
((Sender as TTabControl) .Parent as TWinControl) .Constraints.MaxHeight: = AHeight;
end;
end;
{Adjust the position of the TObjectTreeView and TEditWindow windows each time changing the size of the main form}
procedure TMyExpertObject.UpdateOtherWindows (OldHeight: Integer);
const
WinClasses: array [0.1] of string = (TObjectTreeView, TEditWindow);
var
AForm: TCustomForm;
I, J, MainTop, HeightDelta: Integer;
begin
AForm: = GetIdeMainForm;
if AForm = nil then Exit;
HeightDelta: = AForm.Height - OldHeight;
if HeightDelta = 0 then Exit;
MainTop: = AForm.Top;
for I: = Low (WinClasses) to High (WinClasses) due
begin
// Browse all windows
for J: = 0 to Screen.CustomFormCount - 1 due
begin
// If found, resize
if Screen.CustomForms [J] .ClassNameIs (WinClasses [I]) then
begin
AForm: = Screen.CustomForms [J];
AForm.Top: = AForm.Top + HeightDelta;
AForm.Height: = AForm.Height - HeightDelta;
end;
end;
end;
end;
{Find the main window of Delphi}
function TMyExpertObject.GetIdeMainForm: TCustomForm;
begin
Result: = TForm (Application.FindComponent (AppBuilder));
end;
{Search TAB Component Palette}
function TMyExpertObject.GetTabControl: TTabControl;
var
MainForm: TCustomForm;
begin
Result: = nil;
MainForm: = GetIdeMainForm;
if MainForm <> nil then
Result: = TTabControl (MainForm.FindComponent (TabControl))
end;
{Find popup menu for TAB Component Palette control}
function TMyExpertObject.GetComponentPalettePopupMenu: TPopupMenu;
var
MainForm: TCustomForm;
begin
Result: = nil;
MainForm: = GetIdeMainForm;
if MainForm <> nil then
Result: = TPopupMenu (MainForm.FindComponent (PaletteMenu));
end;
This depends on your subjective mind.
procedure TMyExpertObject.OnMenuPopup (Sender: TObject);
begin
end;
{Settings for the OnClick event of the new selection item in the TAB popup menu}
procedure TMyExpertObject.OnMultiLineItemClick (Sender: TObject);
begin
if Sender is TMenuItem then
begin
MultiLine: = not (Sender as TMenuItem) .Checked;
// Change the Checked status of the selected item
(Sender as TMenuItem) .Checked: = MultiLine;
// Set and record the status into the Registry
SetMultiLineComponentPalette (MultiLine);
SaveSettings;
end;
end;
{Add menu item for popup menu of TAB Component Palette control}
procedure TMyExpertObject.CreateMenuItem (_multiLine: Boolean);
begin
ComponentPaletteMenu: = TPopupMenu.Create (nil);
ComponentPaletteMenu.OnPopup: = OnMenuPopup;
ComponentPaletteMenu: = GetComponentPalettePopupMenu;
// Check the existence of the previous item, if it does not already exist, create a new one
if ComponentPaletteMenu.Items.Find (& Multi-Lines) = nil then
begin
SeperatorItem: = TMenuItem.Create (nil);
SeperatorItem.Caption: = -;
// Add a separator bar
ComponentPaletteMenu.Items.Add (SeperatorItem);
MultiLineItem: = TMenuItem.Create (nil);
MultiLineItem.Checked: = _multiLine;
MultiLineItem.OnClick: = OnMultiLineItemClick;
MultiLineItem.Caption: = & Multi-Lines;
// Add a selection with the name Multi-Lines
ComponentPaletteMenu.Items.Add (MultiLineItem);
end;
end;
{Delete the selection of the popup menu every time the Component is released}
procedure TMyExpertObject.DestroyMenuItem;
var
MI: TMenuItem;
Pos: Integer;
begin
MI: = ComponentPaletteMenu.Items.Find (& Multi-Lines);
if MI <> nil then
begin
Pos: = ComponentPaletteMenu.Items.IndexOf (MI);
ComponentPaletteMenu.Items.Delete (Pos - 1);
ComponentPaletteMenu.Items.Delete (Pos - 1);
end;
end;
{Setting Multi-Lines properties}
procedure TMyExpertObject.SetMultiLineComponentPalette (_multiLine: Boolean);
var
OldHeight: Integer;
begin
App: = GetIdeMainForm;
if App <> nil then
begin
OldHeight: = App.Height;
TabControl: = GetTabControl;
if TabControl <> nil then
begin
TabControl.MultiLine: = _multiLine;
if _multiLine then
begin
TabControl.OnResize: = ResizeMultiLineComponentPalette;
TabControl.OnResize (TabControl);
CreateMenuItem (_multiLine);
end
else
TabControl.OnResize: = nil;
UpdateOtherWindows (OldHeight);
end;
App.Invalidate;
end;
end;
{Calling every time Component is loaded}
initialization
MyExpertObject: = TMyExpertObject.Create (nil);
MyExpertObject.CreateMenuItem (MyExpertObject.MultiLine);
MyExpertObject.SetMultiLineComponentPalette (MyExpertObject.MultiLine);
{The call whenever Component is canceled}
finalization
MyExpertObject.SetMultiLineComponentPalette (False);
MyExpertObject.DestroyMenuItem;
MyExpertObject.Free;
end.
Ngo Quoc Anh
VNU University, Hanoi National University
Email : bookworm_vn@yahoo.com
You should read it
- Learn about Layers Palette in GIMP
- Beautiful hair color palette 2020
- How to Make a Limited Palette in PD Howler
- How to adjust the notification color and iPhone widget
- How to create a custom Color Palette in Adobe Photoshop
- 3 'legitimate' reasons to change DNS Server
- How to open Component Services in Windows 11
- What is RAM? Compare details of phone RAM and laptop RAM
- How to fix 'lsass.exe Unable to Locate Component' error in Windows
- How to change object color with Pixelcut AI Recolor
- 16 programming languages will change your luck
- The terminology of color, wheel color and skill used to color
Maybe you are interested
How to send RCS messages using Google Gemini
How to Find Friends Nearby on Facebook for iPhone, Android
How to Find Friends on Snapchat
Close-up of bullet shattering when fired at 'fragile' pendulum system
How to use the TREND function in Excel
Mozilla considers extending Firefox support on older operating system versions until March 2025