1. Home
  2. Computing & Technology
  3. Delphi Programming

Use TTF Font Without Installing

By , About.com Guide

Here's how to use a TTF (true type font) in your Delphi application without having to install it in Windows:
  1. In the OnCreate event for the main form in your Delphi application call the AddFontResource API function. The AddFontResource function adds the font resource from the specified file to the system font table.
  2. When an application no longer needs a font resource that it loaded by calling the AddFontResource function, it must remove that resource by calling the RemoveFontResource function. Do this in the OnDestroy event for the main form.
procedure TForm1.FormCreate(Sender: TObject) ;
begin

  AddFontResource('c:\FONTS\MyFont.TTF') ;
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;

{Before application terminates we must remove our font:}
procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
begin
  RemoveFontResource('C:\FONTS\MyFont.TTF') ;
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;

Delphi tips navigator:
» Are we connected to the Internet?
« Get Windows version

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2000 Delphi Tips
  7. Use TTF Font Without Installing (in Delphi programs)

©2009 About.com, a part of The New York Times Company.

All rights reserved.