Resources - lendo e salvando fontes |
Top Previous Next |
Carregando e salvando fonte em RES:
procedure TMainForm.FormCreate(Sender: TObject);
{Load Saved fonts to MainForm on Creation}
var FontFile : String; Color : TColor; { Font Colour} Name : String; { Font Name } Size : Integer; { Font Size }
begin
FontFile := 'c:\Fonts.res'; {Set the Directory where the FontFile is kept } AssignFile(F, FontFile); { Set Font File Name }
if FileExists(FontFile) { if the file exists } then begin Reset(F); { Reset pointer to front ready to read } ReadLn(f,Name); { Read each setting, one at a time } MainForm.Font.Name := Name; FontDialog1.Font.Name := Name; ReadLn(F,Size); MainForm.Font.Size := Size; FontDialog1.Font.Size := Size; ReadLn(F,Color); MainForm.Font.Color := Color; FontDialog1.Font.Color := Color; CloseFile(F) { Close the File } end; end; { The main form should now exhibit the font as saved – see next }
procedure TMainForm.Font1Click(Sender: TObject); { Trigger FontDialogue – I used a Menu Item }
begin FontDialog1.Execute { This displays the Font Dialogue } end;
procedure TMainForm.FontDialog1Apply(Sender: TObject; Wnd: HWND);
{ The Apply Button on the Dialogue is used to save the file and set the Main Form Fonts }
var FontFile : String;
begin FontFile := 'c:\Fonts.res'; AssignFile(F, FontFile); Font.Assign(TFontDialog(Sender).Font);
if FileExists(FontFile) { Rewrite existing File } then begin Rewrite(F); WriteLn(F,MainForm.Font.Name); WriteLn(F,MainForm.Font.Size); WriteLn(F,MainForm.Font.Color); CloseFile(F) end else begin Rewrite(F); { or make a new onr } WriteLn(F,MainForm.Font.Name); WriteLn(F,MainForm.Font.Size); WriteLn(F,MainForm.Font.Color); CloseFile(F); Font.Assign(TFontDialog(Sender).Font) { Now assign the Font changes } end; end; |