» Help

Code Snippets Database

Control Box
 
 

Requested snippets

This page displays 7 requested snippets.

You can choose a category, perform a search or generate a Pascal unit containing the snippets by using the Control Box.

FontExists
Checks if a named font exists on the sytem.
function FontExists(const FontName: string): Boolean;
begin
  Result := Forms.Screen.Fonts.IndexOf(FontName) >= 0;
end;
Kind of Snippet: Routine
Required units: Forms.
Required snippets: None.
See also: None.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
IsTrueTypeFont_A
Checks if a font is a true type font.
function IsTrueTypeFont(const Font: Graphics.TFont): Boolean; overload;
var
  DC: Windows.HDC;          // device context in which font is selected
  TM: Windows.TTextMetric;  // text metrics for font in DC
begin
  DC := CreateDisplayDC;
  try
    Windows.SelectObject(DC, Font.Handle);
    Windows.GetTextMetrics(DC, TM);
    Result := IsFlagSet(TM.tmPitchAndFamily, Windows.TMPF_TRUETYPE);
  finally
    Windows.DeleteDC(DC);
  end;
end;
Kind of Snippet: Routine
Required units: Windows, Graphics.
Required snippets: CreateDisplayDC, IsFlagSet, [Show All].
See also: IsTrueTypeFont_B.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Red LED Red LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
This snippet cannot be included in generated units.
IsTrueTypeFont_B
Checks if a named font is a true type font.
function IsTrueTypeFont(const FontName: string): Boolean; overload;
var
  Font: Graphics.TFont;
begin
  Font := Graphics.TFont.Create;
  try
    Font.Name := FontName;
    Result := IsTrueTypeFont(Font);
  finally
    Font.Free;
  end;
end;
Kind of Snippet: Routine
Required units: Graphics.
Required snippets: IsTrueTypeFont_A.
See also: IsTrueTypeFont_A.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Red LED Red LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
This snippet cannot be included in generated units.
SetDefaultFont
Sets a font to the default GUI font for the operating system.
procedure SetDefaultFont(const AFont: Graphics.TFont);
begin
  AFont.Handle := Windows.GetStockObject(Windows.DEFAULT_GUI_FONT);
end;
Kind of Snippet: Routine
Required units: Windows, Graphics.
Required snippets: None.
See also: SetDesktopIconFont.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
From Bill Miller's snippets collection.
SetDesktopIconFont
Sets a font to the font used for desktop icons on the operating system. If the required font is not supported by the OS then the system default GUI font is used.
procedure SetDesktopIconFont(const AFont: Graphics.TFont);
var
  LogFont: Windows.TLogFont;  // structure containing desktop icon font info
begin
  if Windows.SystemParametersInfo(
    Windows.SPI_GETICONTITLELOGFONT, SizeOf(LogFont), @LogFont, 0) then
    AFont.Handle := Windows.CreateFontIndirect(LogFont)
  else
    SetDefaultFont(AFont);
end;
Kind of Snippet: Routine
Required units: Windows, Graphics.
Required snippets: SetDefaultFont.
See also: SetDefaultFont.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
Adapted from code from Bill Miller's code snippets collection.
SetVistaContentFont
Sets a given font to the Vista content font and adjusts the font's size accordingly. Does nothing if (1) the operating system is not at least Vista, (2) the Vista content font is not available or (3) the font is already the required content font.
procedure SetVistaContentFont(const AFont: Graphics.TFont);
const
  VistaContentFont = 'Calibri'; // name of Vista content font
begin
  if (SysUtils.Win32MajorVersion >= 6) 
    and not SysUtils.SameText(AFont.Name, VistaContentFont)
    and FontExists(VistaContentFont) then
  begin
    AFont.Size := AFont.Size + 2;
    AFont.Name := VistaContentFont;
  end;
end;
Kind of Snippet: Routine
Required units: SysUtils, Graphics.
Required snippets: FontExists.
See also: SetVistaFont.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Red LED Red LED Red LED Grey LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
Adapted from code from the article Creating Windows Vista Ready Applications with Delphi.
SetVistaFont
Sets a given font to the Vista default font and adjusts the font's size accordingly. Does nothing if (1) the operating system is not at least Vista, (2) default Vista font is not available or (3) the font is already the Vista default font.
procedure SetVistaFont(const AFont: Graphics.TFont);
const
  VistaFont = 'Segoe UI'; // name of main Vista font
begin
  if (SysUtils.Win32MajorVersion >= 6) 
    and not SysUtils.SameText(AFont.Name, VistaFont)
    and FontExists(VistaFont) then
  begin
    AFont.Size := AFont.Size + 1;
    AFont.Name := VistaFont;
  end;
end;
Kind of Snippet: Routine
Required units: SysUtils, Graphics.
Required snippets: FontExists.
Supported Compilers:
 D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Free
Pascal
Red LED Red LED Red LED Grey LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Red LED
Adapted from code from the article Creating Windows Vista Ready Applications with Delphi.