Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Delphi - How to use your own font (ttf) in your app without installing it.

1 Posts
1 Users
0 Likes
7,829 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2697
Topic starter  

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. 
(this does not [yet] work in Lazarus)

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.

 procedure TForm1.FormCreate(Sender: TObject) ;
begin
AddFontResource('c:FONTSMyFont.TTF') ;
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;
{Remove font again on program termination}
procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
begin
RemoveFontResource('C:FONTSMyFont.TTF') ;
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;


   
ReplyQuote
Share: