Return to Snippet

Revision: 64944
at October 7, 2013 17:05 by ebta


Initial Code
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;

Initial URL


Initial Description
Here's how to use a TTF (true type font) in your Delphi application without having to install it in Windows:
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.
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.

Initial Title
Use TTF Font Without Installing

Initial Tags


Initial Language
Delphi