Include font from from a resource file

Posted in Resource

You should include {$R MyNewFont.RES} line to the implementation section. For causing from a resource font is necessary to create an object of TResorceStream type and to add font with AddFontResource procedure. And for including font you should use the WM_FONTCHANGE message. There is a 'MYFONT' section which contents a font file in the resource file.

{$R MyNewFont.RES}
...
procedure TForm1.FormCreate(Sender: TObject);
var
  MyResStream: TResourceStream;
begin
  MyResStream:=TResourceStream.Create(hInstance, 'MYFONT', RT_RCDATA);
  MyResStream.SavetoFile('Gen4.ttf');
  AddFontResource(PChar('Gen4.ttf'));
  SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
  Label1.Font.Charset:=SYMBOL_CHARSET;
  Label1.Font.Size:=24;
  Label1.Font.Name:='Gen4';
end;