1. Create RC file (e.g MY.RC) MYFONT RCDATA "FONT_FILE_NAME" 2. Compile RC file using BRCC32 MY.RC 3. Add compiler directive {$R MY.RES} 4. Use below code in OnCreate and OnDestroy events procedure TForm1.FormCreate(Sender: TObject); var res: TResourceStream; begin res := TResourceStream.Create(hInstance, 'MYFONT', RT_RCDATA); try res.SavetoFile('myfont.ttf'); finally res.Free; end; AddFontResource(PChar('myfont.ttf')); SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0); //Now you use your own font Label1.Font.Size:=24; Label1.Font.Name:='myfont'; end;//We don't want this font to be available after our application is closedprocedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ; begin RemoveFontResource('PATH_TO_MyFont.TTF') ; SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ; end; Remeber Font's can be directly used from memory. We have to save them to file and call AddFontResource API function. The AddFontResource function adds the font resource from the specified file to the system font table. We need to fake this font adding and we should broadcast WM_FONTCHANGE message.When we don't need this font we must call RemoveFontResource function to remove this resource.Hope it helpsThanks,Ali
Correction:Remember Font's can be SHOULD be read as Font's CAN'T be
Ali 啊 procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ; 中 var Action: TCloseAction 部分 通不过 。屏蔽后 字体没有变化啊http://ishare.iask.sina.com.cn/f/14569194.html?w=' target='_blank'>字体资源.rar 我把工程文件传到网上了。 是 D7的
It is working :). Please change the font of label1 at design time to something different like "Arial". Run the application and you will see font is changed to Trana.ttf font (Transponder AOE).You will have to write the actual Font name instead of providing the ttf file name. Label1.Font.Size:=24; Label1.Font.Name:='Transponder AOE';
thank you very much ! I think the name of the font is so long, it is not the font name.
MYFONT RCDATA "FONT_FILE_NAME"
2. Compile RC file using BRCC32 MY.RC
3. Add compiler directive {$R MY.RES}
4. Use below code in OnCreate and OnDestroy events
procedure TForm1.FormCreate(Sender: TObject);
var
res: TResourceStream;
begin
res := TResourceStream.Create(hInstance, 'MYFONT', RT_RCDATA);
try
res.SavetoFile('myfont.ttf');
finally
res.Free;
end;
AddFontResource(PChar('myfont.ttf'));
SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
//Now you use your own font
Label1.Font.Size:=24;
Label1.Font.Name:='myfont';
end;//We don't want this font to be available after our application is closedprocedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
begin
RemoveFontResource('PATH_TO_MyFont.TTF') ;
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;
Remeber Font's can be directly used from memory. We have to save them to file and call AddFontResource API function. The AddFontResource function adds the font resource from the specified file to the system font table. We need to fake this font adding and we should broadcast WM_FONTCHANGE message.When we don't need this font we must call RemoveFontResource function to remove this resource.Hope it helpsThanks,Ali
中 var Action: TCloseAction 部分 通不过 。屏蔽后 字体没有变化啊http://ishare.iask.sina.com.cn/f/14569194.html?w=' target='_blank'>字体资源.rar 我把工程文件传到网上了。 是 D7的
Label1.Font.Size:=24;
Label1.Font.Name:='Transponder AOE';
but, it is.
thanks!
中 var Action: TCloseAction 部分 通不过 。