Skip to content

TSVGIconSourceItem (FMX) ​

Unit: FMX.SVGIconImageList

Inherits from: TCustomSourceItem

Description ​

TSVGIconSourceItem represents a single SVG icon within a TSVGIconImageList's Source collection. Each source item stores the original SVG content and rendering attributes (color, opacity, grayscale), and manages the generation of multi-resolution bitmaps for different scales and sizes.

Source items are created automatically when you add icons to TSVGIconImageList using methods like AddIcon, InsertIcon, or LoadFromFiles.

Properties ​

Identification ​

IconName: String ​

pascal
property IconName: string read GetIconName write SetIconName;

Unique name for the icon. Used to retrieve icons by name using GetIconByName.

Example:

pascal
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIcon(0);
  Icon.IconName := 'home';

  // Later retrieve by name
  Icon := SVGIconImageList1.GetIconByName('home');
end;

SVG Content ​

SVGText: String ​

pascal
property SVGText: string read GetSVGText write SetSVGText;

The SVG XML content as a string.

Example:

pascal
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIcon(0);
  Icon.SVGText := '<svg width="100" height="100">...</svg>';
end;

SVG: TFmxImageSVG ​

pascal
property SVG: TFmxImageSVG read FSVG write SetSVG;

Direct access to the underlying TFmxImageSVG object for advanced manipulation.

Example:

pascal
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIcon(0);
  Icon.SVG.FixedColor := TAlphaColorRec.Blue;
  Icon.SVG.Opacity := 0.8;
end;

Rendering Attributes ​

FixedColor: TAlphaColor ​

pascal
property FixedColor: TAlphaColor read GetFixedColor write SetFixedColor default TAlphaColors.Null;

Override all colors in this icon's SVG with a fixed color. Use TAlphaColors.Null to inherit from ImageList or preserve original colors.

Example:

pascal
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIconByName('warning');
  Icon.FixedColor := TAlphaColorRec.Orange;
end;

ApplyFixedColorToRootOnly: Boolean ​

pascal
property ApplyFixedColorToRootOnly: Boolean read FApplyFixedColorToRootOnly write SetApplyFixedColorToRootOnly default False;

When True, applies FixedColor only to the root SVG element. Default: False.

Example:

pascal
Icon.FixedColor := TAlphaColorRec.Blue;
Icon.ApplyFixedColorToRootOnly := True; // Only root element becomes blue

GrayScale: Boolean ​

pascal
property GrayScale: Boolean read GetGrayScale write SetGrayScale default False;

Renders this icon in grayscale. Default: False.

Example:

pascal
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIconByName('disabled-feature');
  Icon.GrayScale := True; // Show as disabled
end;

Opacity: Single ​

pascal
property Opacity: Single read GetOpacity write SetOpacity;

Opacity for this icon (0.0 = transparent, 1.0 = opaque). Default: -1 (inherit from ImageList).

Example:

pascal
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIcon(0);
  Icon.Opacity := 0.5; // 50% transparent
end;

Multi-Resolution Bitmap ​

MultiResBitmap: TSVGIconMultiResBitmap ​

pascal
property MultiResBitmap: TSVGIconMultiResBitmap;

The multi-resolution bitmap collection for this icon. Contains rendered bitmaps at different scales (1x, 1.5x, 2x, 3x).

Example:

pascal
var
  Icon: TSVGIconSourceItem;
  BitmapItem: TSVGIconBitmapItem;
begin
  Icon := SVGIconImageList1.GetIcon(0);

  // Access specific scale bitmap
  BitmapItem := Icon.MultiResBitmap.ItemByScale(2.0, False) as TSVGIconBitmapItem;
  if Assigned(BitmapItem) then
    ShowMessage(Format('2x bitmap: %dx%d', [BitmapItem.Width, BitmapItem.Height]));
end;

Methods ​

Assign ​

pascal
procedure Assign(Source: TPersistent); override;

Copies all properties from another TPersistent object.

Example:

pascal
var
  SourceIcon, DestIcon: TSVGIconSourceItem;
begin
  SourceIcon := SVGIconImageList1.GetIcon(0);
  DestIcon := SVGIconImageList1.GetIcon(1);
  DestIcon.Assign(SourceIcon); // Copy all properties
end;

Usage Examples ​

Customize Individual Icon ​

pascal
procedure TForm1.CustomizeHomeIcon;
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIconByName('home');
  if Assigned(Icon) then
  begin
    Icon.FixedColor := TAlphaColorRec.Blue;
    Icon.Opacity := 0.9;
    SVGIconImageList1.RefreshAllIcons; // Apply changes
  end;
end;

Mark Icons as Disabled ​

pascal
procedure TForm1.DisableIcon(const AName: string);
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIconByName(AName);
  if Assigned(Icon) then
  begin
    Icon.GrayScale := True;
    Icon.Opacity := 0.5;
    SVGIconImageList1.RefreshAllIcons;
  end;
end;

Iterate Through All Icons ​

pascal
procedure TForm1.ListAllIcons;
var
  I: Integer;
  Icon: TSVGIconSourceItem;
begin
  Memo1.Lines.Clear;
  for I := 0 to SVGIconImageList1.Source.Count - 1 do
  begin
    Icon := SVGIconImageList1.Source[I] as TSVGIconSourceItem;
    Memo1.Lines.Add(Format('%d: %s', [I, Icon.IconName]));
  end;
end;

Apply Color Theme ​

pascal
procedure TForm1.ApplyColorScheme(const ACategory: string; AColor: TAlphaColor);
var
  I: Integer;
  Icon: TSVGIconSourceItem;
begin
  for I := 0 to SVGIconImageList1.Source.Count - 1 do
  begin
    Icon := SVGIconImageList1.Source[I] as TSVGIconSourceItem;

    // Apply color to icons in specific category
    if Icon.IconName.StartsWith(ACategory + '\') then
      Icon.FixedColor := AColor;
  end;

  SVGIconImageList1.RefreshAllIcons;
end;

Clone and Modify Icon ​

pascal
procedure TForm1.CreateVariation;
var
  OrigIcon, NewIcon: TSVGIconSourceItem;
begin
  // Get original
  OrigIcon := SVGIconImageList1.GetIconByName('star');

  // Clone
  NewIcon := SVGIconImageList1.CloneIcon(
    SVGIconImageList1.Source.IndexOf(OrigIcon)
  );

  // Customize clone
  NewIcon.IconName := 'star-yellow';
  NewIcon.FixedColor := TAlphaColorRec.Yellow;

  SVGIconImageList1.RefreshAllIcons;
end;

Replace Icon Content ​

pascal
procedure TForm1.UpdateIcon(const AName: string; const ANewSVG: string);
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIconByName(AName);
  if Assigned(Icon) then
  begin
    Icon.SVGText := ANewSVG;
    SVGIconImageList1.RefreshAllIcons;
  end;
end;

Conditional Formatting ​

pascal
procedure TForm1.ApplyStatusColor(const AIconName: string; AStatus: TStatusType);
var
  Icon: TSVGIconSourceItem;
begin
  Icon := SVGIconImageList1.GetIconByName(AIconName);
  if not Assigned(Icon) then Exit;

  case AStatus of
    stNormal:
      begin
        Icon.FixedColor := TAlphaColors.Null; // Original colors
        Icon.GrayScale := False;
        Icon.Opacity := 1.0;
      end;
    stWarning:
      begin
        Icon.FixedColor := TAlphaColorRec.Orange;
        Icon.GrayScale := False;
        Icon.Opacity := 1.0;
      end;
    stError:
      begin
        Icon.FixedColor := TAlphaColorRec.Red;
        Icon.GrayScale := False;
        Icon.Opacity := 1.0;
      end;
    stDisabled:
      begin
        Icon.FixedColor := TAlphaColors.Null;
        Icon.GrayScale := True;
        Icon.Opacity := 0.5;
      end;
  end;

  SVGIconImageList1.RefreshAllIcons;
end;

Extract SVG for Standalone Use ​

pascal
procedure TForm1.ExtractAndUse;
var
  Icon: TSVGIconSourceItem;
  SVG: TFmxImageSVG;
  Bitmap: TBitmap;
begin
  Icon := SVGIconImageList1.GetIconByName('export');
  SVG := Icon.SVG;

  // Use SVG directly
  Bitmap := TBitmap.Create(256, 256);
  try
    SVG.PaintToBitmap(Bitmap, 100);
    Bitmap.SaveToFile('exported.png');
  finally
    Bitmap.Free;
  end;
end;

Property Inheritance ​

When a property is set to its default value, it inherits from the parent TSVGIconImageList:

PropertyDefault ValueInheritance Behavior
FixedColorTAlphaColors.NullInherits from ImageList.FixedColor
GrayScaleFalseInherits from ImageList.GrayScale
Opacity-1Inherits from ImageList.Opacity
ApplyFixedColorToRootOnlyFalseThe icon value is used when the icon has its own FixedColor, the ImageList value when it inherits the color

From version 4.8.0 only the values of the icon itself are stored into the form: an inherited value stays inherited when the form is read back (before, it was stored as a value of the icon, and a later change of the ImageList had no effect on it).

Example:

pascal
// ImageList settings
SVGIconImageList1.FixedColor := TAlphaColorRec.Blue;
SVGIconImageList1.Opacity := 0.8;

// Icon with defaults inherits ImageList settings
Icon1.FixedColor := TAlphaColors.Null; // Uses Blue from ImageList
Icon1.Opacity := -1; // Uses 0.8 from ImageList

// Icon with explicit values overrides ImageList
Icon2.FixedColor := TAlphaColorRec.Red; // Uses Red
Icon2.Opacity := 1.0; // Uses 1.0

See Also ​

Released under Apache License, Version 2.0.