Posted By

ebta on 10/07/13



Versions (?)

Use TTF Font Without Installing

 / Published in: Delphi

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.

  1. procedure TForm1.FormCreate(Sender: TObject) ;
  2. begin
  4. AddFontResource('c:\FONTS\MyFont.TTF') ;
  5. SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
  6. end;
  8. {Before application terminates we must remove our font:}
  9. procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
  10. begin
  11. RemoveFontResource('C:\FONTS\MyFont.TTF') ;
  12. SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
  13. end;

Report this snippet  

You need to login to post a comment.