Skip to content

TSVGIconImageCollection ​

Unit: SVGIconImageCollection

Inherits from: TCustomImageCollection (Delphi 10.3+) or TComponent

Minimum Delphi Version: 10.3 Rio (for full VirtualImageList integration)

Description ​

TSVGIconImageCollection is a modern VCL component for storing and managing collections of SVG icons. It follows Delphi's ImageCollection/VirtualImageList architecture introduced in Delphi 10.3, allowing multiple TSVGIconVirtualImageList components to share the same icon source at different sizes.

Unlike TSVGIconImageList which contains both storage and rendering, TSVGIconImageCollection only stores SVG icons. Rendering is performed by linked TSVGIconVirtualImageList components, enabling efficient memory usage when the same icons are needed at multiple sizes.

Published Properties ​

Icon Collection ​

SVGIconItems ​

pascal
property SVGIconItems: TSVGIconItems;

Collection of SVG icon items. Each item contains an SVG image and associated properties.

Usage:

pascal
// Access items
var Item := SVGIconImageCollection1.SVGIconItems[0];

// Count
Label1.Caption := Format('%d icons', [SVGIconImageCollection1.SVGIconItems.Count]);

Default Rendering Attributes ​

These properties set default rendering attributes for all icons. Individual icons can override these settings.

FixedColor ​

pascal
property FixedColor: TColor;

Default fixed color for all icons. Default: SVG_INHERIT_COLOR

Usage:

pascal
SVGIconImageCollection1.FixedColor := clBlue;

ApplyFixedColorToRootOnly ​

pascal
property ApplyFixedColorToRootOnly: Boolean;

Apply FixedColor only to root SVG elements. Default: False

Usage:

pascal
SVGIconImageCollection1.FixedColor := clRed;
SVGIconImageCollection1.ApplyFixedColorToRootOnly := True;

GrayScale ​

pascal
property GrayScale: Boolean;

Render all icons in grayscale. Default: False

Usage:

pascal
SVGIconImageCollection1.GrayScale := True;

Opacity ​

pascal
property Opacity: Byte;

Default opacity for all icons (0-255). Default: 255

Usage:

pascal
SVGIconImageCollection1.Opacity := 200;

AntiAliasColor ​

pascal
property AntiAliasColor: TColor;

Background color for anti-aliasing. Default: clBtnFace

Usage:

pascal
SVGIconImageCollection1.AntiAliasColor := clWhite;

Public Methods ​

Create / Destroy ​

pascal
constructor Create(AOwner: TComponent);
destructor Destroy; override;

Icon Management ​

Add ​

pascal
function Add(const ASVG: ISVG; const AIconName: string;
  const AGrayScale: Boolean = False;
  const AFixedColor: TColor = SVG_INHERIT_COLOR;
  const AApplyToRootOnly: Boolean = False): Integer;

Adds a new SVG icon to the collection and returns its index.

Parameters:

  • ASVG: SVG interface to add
  • AIconName: Name for the icon
  • AGrayScale: Render this icon in grayscale
  • AFixedColor: Fixed color for this icon
  • AApplyToRootOnly: Apply fixed color only to root element

Returns: Index of the newly added icon

Usage:

pascal
var
  SVG: ISVG;
  Index: Integer;
begin
  SVG := GlobalSVGFactory.NewSvg;
  SVG.LoadFromFile('home.svg');
  Index := SVGIconImageCollection1.Add(SVG, 'home');
end;

Delete ​

pascal
procedure Delete(const Index: Integer);

Deletes the icon at the specified index.

Usage:

pascal
SVGIconImageCollection1.Delete(0);

Delete (range with optional category filter) ​

pascal
procedure Delete(const ACategory: String; AStartIndex, AEndIndex: Integer);

Deletes a range of icons, optionally filtered by category.

Parameters:

  • ACategory: Category to filter (empty string = all categories)
  • AStartIndex: Starting index (inclusive)
  • AEndIndex: Ending index (inclusive)

Usage:

pascal
// Delete icons 5-10
SVGIconImageCollection1.Delete('', 5, 10);

// Delete icons 0-4 in 'Navigation' category
SVGIconImageCollection1.Delete('Navigation', 0, 4);

Remove ​

pascal
procedure Remove(const Name: string);

Removes the icon with the specified name.

Usage:

pascal
SVGIconImageCollection1.Remove('home');
SVGIconImageCollection1.Remove('Navigation\home');

IndexOf ​

pascal
function IndexOf(const Name: string): Integer;

Returns the index of the named icon, or -1 if not found.

Usage:

pascal
var
  Index: Integer;
begin
  Index := SVGIconImageCollection1.IndexOf('settings');
  if Index >= 0 then
    ShowMessage('Found at index: ' + IntToStr(Index));
end;

ClearIcons ​

pascal
procedure ClearIcons;

Removes all icons from the collection.

Usage:

pascal
SVGIconImageCollection1.ClearIcons;

File Operations ​

LoadFromFile ​

pascal
function LoadFromFile(const AFileName: string; out AImageName: string): TSVGIconItem;

Loads an SVG from a file and returns the created item.

Parameters:

  • AFileName: Path to SVG file
  • AImageName: Receives the name of the loaded icon (filename without extension)

Returns: The newly created TSVGIconItem

Usage:

pascal
var
  Item: TSVGIconItem;
  ImageName: string;
begin
  Item := SVGIconImageCollection1.LoadFromFile('C:\Icons\home.svg', ImageName);
  ShowMessage('Loaded as: ' + ImageName);
end;

LoadFromFiles ​

pascal
function LoadFromFiles(const AFileNames: TStrings; const AAppend: Boolean = True): Integer;

Loads multiple SVG files and returns the count loaded.

Parameters:

  • AFileNames: List of file paths
  • AAppend: If True, append to existing icons; if False, clear first

Returns: Number of icons successfully loaded

Usage:

pascal
var
  Files: TStringList;
  Count: Integer;
begin
  Files := TStringList.Create;
  try
    Files.LoadFromFile('iconlist.txt');
    Count := SVGIconImageCollection1.LoadFromFiles(Files, True);
    ShowMessage(Format('Loaded %d icons', [Count]));
  finally
    Files.Free;
  end;
end;

SaveToFile ​

pascal
function SaveToFile(const AFileName: string; const AImageName: string): Boolean;

Saves a named icon to a file.

Parameters:

  • AFileName: Target file path
  • AImageName: Name of the icon to save

Returns: True if successful

Usage:

pascal
if SVGIconImageCollection1.SaveToFile('C:\Export\home.svg', 'home') then
  ShowMessage('Icon saved successfully');

Resource Operations ​

LoadFromResource ​

pascal
function LoadFromResource(const hInstance: THandle;
  const ResourceName: string; const IconName: string): Integer;

Loads an SVG from a compiled resource.

Parameters:

  • hInstance: Module handle (use HInstance for current executable)
  • ResourceName: Name of the resource
  • IconName: Name to assign to the loaded icon

Returns: Index of the loaded icon

Usage:

pascal
// Add SVG to resources first (.rc file):
// HOME_ICON SVG "home.svg"

Index := SVGIconImageCollection1.LoadFromResource(HInstance, 'HOME_ICON', 'home');

LoadFromString ​

pascal
function LoadFromString(const Source: string; const IconName: string): Integer;

Loads an SVG from an XML string.

Parameters:

  • Source: SVG XML content
  • IconName: Name to assign to the icon

Returns: Index of the loaded icon

Usage:

pascal
const
  HomeSVG = '<svg width="24" height="24"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>';
begin
  Index := SVGIconImageCollection1.LoadFromString(HomeSVG, 'home');
end;

Rendering Attributes ​

SetColors ​

pascal
procedure SetColors(const AFixedColor: TColor = SVG_INHERIT_COLOR;
  const AApplyToRootOnly: Boolean = False;
  const AAntiAliasColor: TColor = clBtnFace);

Sets color attributes for the entire collection.

Usage:

pascal
SVGIconImageCollection1.SetColors(clBlue, False, clWhite);

UpdateAttributes (Delphi 10.3+) ​

pascal
procedure UpdateAttributes(AFixedColor: TColor;
  AApplyFixedColorToRootOnly: Boolean; AGrayScale: Boolean;
  AAntiAliasColor: TColor; AOpacity: Byte);

Updates all rendering attributes at once.

Usage:

pascal
SVGIconImageCollection1.UpdateAttributes(
  clBlue,  // FixedColor
  False,   // ApplyToRootOnly
  False,   // GrayScale
  clWhite, // AntiAliasColor
  255      // Opacity
);

Access Methods (Delphi 10.3+) ​

IsIndexAvailable ​

pascal
function IsIndexAvailable(AIndex: Integer): Boolean;

Checks if an index is valid.

Usage:

pascal
if SVGIconImageCollection1.IsIndexAvailable(5) then
  ShowMessage('Index 5 exists');

GetIndexByName ​

pascal
function GetIndexByName(const AName: String): Integer;

Gets the index of a named icon.

Usage:

pascal
Index := SVGIconImageCollection1.GetIndexByName('home');

GetNameByIndex ​

pascal
function GetNameByIndex(AIndex: Integer): String;

Gets the name of an icon by index.

Usage:

pascal
Name := SVGIconImageCollection1.GetNameByIndex(0);

Drawing ​

Draw ​

pascal
procedure Draw(ACanvas: TCanvas; ARect: TRect; AIndex: Integer;
  AProportional: Boolean = False);

Draws an icon directly to a canvas.

Parameters:

  • ACanvas: Target canvas
  • ARect: Rectangle to draw in
  • AIndex: Icon index
  • AProportional: Maintain aspect ratio

Usage:

pascal
SVGIconImageCollection1.Draw(
  Canvas,
  Rect(10, 10, 74, 74),
  0,
  True
);

GetBitmap (Delphi 10.3+) ​

pascal
function GetBitmap(AIndex: Integer; AWidth, AHeight: Integer): TBitmap;

Returns a bitmap representation of an icon.

Parameters:

  • AIndex: Icon index
  • AWidth, AHeight: Desired bitmap size

Returns: New TBitmap instance (caller must free)

Usage:

pascal
var
  Bitmap: TBitmap;
begin
  Bitmap := SVGIconImageCollection1.GetBitmap(0, 48, 48);
  try
    Image1.Picture.Assign(Bitmap);
  finally
    Bitmap.Free;
  end;
end;

Miscellaneous ​

Assign ​

pascal
procedure Assign(Source: TPersistent); override;

Assigns content from another collection.

Usage:

pascal
SVGIconImageCollection2.Assign(SVGIconImageCollection1);

Examples ​

Basic Setup with Virtual ImageLists ​

pascal
procedure TForm1.FormCreate(Sender: TObject);
begin
  // Load icons into collection (once)
  var Files := TStringList.Create;
  try
    Files.Add('icons\home.svg');
    Files.Add('icons\settings.svg');
    Files.Add('icons\exit.svg');
    SVGIconImageCollection1.LoadFromFiles(Files);
  finally
    Files.Free;
  end;

  // Configure small icons (16x16)
  SVGIconVirtualImageListSmall.ImageCollection := SVGIconImageCollection1;
  SVGIconVirtualImageListSmall.Size := 16;

  // Configure large icons (48x48)
  SVGIconVirtualImageListLarge.ImageCollection := SVGIconImageCollection1;
  SVGIconVirtualImageListLarge.Size := 48;

  // Use with controls
  ToolBar1.Images := SVGIconVirtualImageListSmall;
  ListView1.LargeImages := SVGIconVirtualImageListLarge;

  // Same icons, different sizes, shared storage!
end;

Dynamic Icon Loading ​

pascal
procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    var ImageName: string;
    SVGIconImageCollection1.LoadFromFile(OpenDialog1.FileName, ImageName);
    ListBox1.Items.Add(ImageName);
  end;
end;

Icon Organization with Categories ​

pascal
procedure TForm1.LoadCategorizedIcons;
var
  SVG: ISVG;
begin
  SVG := GlobalSVGFactory.NewSvg;

  // Navigation category
  SVG.LoadFromFile('home.svg');
  SVGIconImageCollection1.Add(SVG, 'home', 'Navigation');

  SVG.LoadFromFile('back.svg');
  SVGIconImageCollection1.Add(SVG, 'back', 'Navigation');

  // Actions category
  SVG.LoadFromFile('save.svg');
  SVGIconImageCollection1.Add(SVG, 'save', 'Actions');

  SVG.LoadFromFile('delete.svg');
  SVGIconImageCollection1.Add(SVG, 'delete', 'Actions');

  // Icons are named: Navigation\home, Navigation\back, Actions\save, Actions\delete
end;

Theme Support ​

pascal
procedure TForm1.ApplyTheme(ADarkMode: Boolean);
begin
  if ADarkMode then
  begin
    SVGIconImageCollection1.FixedColor := clWhite;
    SVGIconImageCollection1.AntiAliasColor := $202020;
  end
  else
  begin
    SVGIconImageCollection1.FixedColor := clBlack;
    SVGIconImageCollection1.AntiAliasColor := clWhite;
  end;

  // All linked virtual image lists automatically update
end;

Batch Icon Import ​

pascal
procedure TForm1.ImportIconsFromDirectory(const APath: string);
var
  Files: TStringList;
  SR: TSearchRec;
begin
  Files := TStringList.Create;
  try
    if FindFirst(TPath.Combine(APath, '*.svg'), faAnyFile, SR) = 0 then
    begin
      repeat
        Files.Add(TPath.Combine(APath, SR.Name));
      until FindNext(SR) <> 0;
      FindClose(SR);
    end;

    var Count := SVGIconImageCollection1.LoadFromFiles(Files, True);
    ShowMessage(Format('Imported %d icons', [Count]));
  finally
    Files.Free;
  end;
end;

Custom Drawing ​

pascal
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
  R: TRect;
  I: Integer;
begin
  // Draw icon grid
  for I := 0 to SVGIconImageCollection1.SVGIconItems.Count - 1 do
  begin
    R := Rect(
      (I mod 4) * 64,
      (I div 4) * 64,
      (I mod 4) * 64 + 64,
      (I div 4) * 64 + 64
    );
    SVGIconImageCollection1.Draw(PaintBox1.Canvas, R, I, True);
  end;
end;

Export Collection ​

pascal
procedure TForm1.ExportAllIcons(const AOutputPath: string);
var
  I: Integer;
  IconName, FileName: string;
begin
  ForceDirectories(AOutputPath);

  for I := 0 to SVGIconImageCollection1.SVGIconItems.Count - 1 do
  begin
    IconName := SVGIconImageCollection1.GetNameByIndex(I);
    FileName := TPath.Combine(AOutputPath, IconName + '.svg');

    // Create subdirectories for categories
    ForceDirectories(ExtractFilePath(FileName));

    SVGIconImageCollection1.SaveToFile(FileName, IconName);
  end;

  ShowMessage(Format('Exported %d icons', [SVGIconImageCollection1.SVGIconItems.Count]));
end;

Notes ​

Benefits of ImageCollection Architecture ​

  1. Memory Efficiency: Store icons once, render at multiple sizes
  2. Centralized Management: Update all icon lists by changing the collection
  3. Design-Time Preview: Visual editing in the IDE
  4. Standard Integration: Works with VCL's Virtual ImageList system

Comparison with TSVGIconImageList ​

FeatureTSVGIconImageCollectionTSVGIconImageList
StorageYesYes
RenderingNo (via VirtualImageList)Yes
Delphi Version10.3+XE6+
Multiple SizesYes (efficient)No (need separate lists)
Memory UsageLower (shared storage)Higher (per list)
ComplexityModerate (2 components)Simple (1 component)

When to Use ​

Use TSVGIconImageCollection when:

  • Using Delphi 10.3 or later
  • Need same icons at multiple sizes
  • Want centralized icon management
  • Building modern applications

Use TSVGIconImageList when:

  • Supporting older Delphi versions (XE6-10.2)
  • Simple single-size icon lists
  • Quick prototyping
  • Legacy code migration

See Also ​

Released under Apache License, Version 2.0.