Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 831
  • Last Modified:

Font-dialog problem

Dear Experts,

On my form I have my own component named MyDrawingPanel1.
and on the MyDrawingPanel1 component I have a FontDialog-
component. Now, when I open the fontdialog-window by chosing
menu-item Change Font, the Edit-boxes FontStyle and FontSize  gets filled but the Edit-box Font is empy!!! What have I done wrong ?

In de MyDrawingPanel1.unit I have declared:

var
    FontName: string;
    FontSize: integer;

constructor Create(AOwner: TComponent); override;
begin
...
  Font.Size := FontSize;
  Font.Name := FontName;
...
end

procedure TMyDrawingPanel.Paint;
var
  TxMetric: TTextMetric;
begin
  Canvas.Font.Size := FontSize;
  Canvas.Font.Name := FontName;
  GetTextMetrics(Canvas.Handle, TxMetric);
  FontWidthPix := TxMetric.tmAveCharWidth;
  FontHeightPix := TxMetric.tmHeight;
  Showbuf;
end;

On the mainform I have declared:

procedure TMainForm.FormCreate(Sender: TObject);
begin
...
  AddFontResource(PChar('FTPREG.TTF'));
  AddFontResource(PChar('FTP132.TTF'));
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
...
end;

procedure TMainForm.ChangeFont1Click(Sender: TObject);
begin
  FontDialog1.Font.Name := MyDrawingPanel1.FontName;
  FontDialog1.Font.Size := MyDrawingPanel1.FontSize;
  if FontDialog1.Execute() then
  begin
    MyDrawingPanel1.FontName := FontDialog1.Font.Name;
    MyDrawingPanel1.FontSize := FontDialog1.Font.Size;
    MyDrawingPanel1.Invalidate;
  end;
end;

In de unit Optionsu are procedures to save and get data
from file:

procedure SaveOptions(FName: string);
var
  OptFile: TextFile;
  i: integer;
begin
  AssignFile(OptFile, FName);
  ReWrite(OptFile);
  WriteLn(OptFile, '******************************');
  WriteLn(OptFile, '* Emu3270 Configuration Options     *');
  WriteLn(OptFile, '******************************');
  WriteLn(OptFile, '*');
  WriteLn(OptFile, 'w HostName ', ConnectHostName);
  WriteLn(OptFile, 's FontName ', MainForm.MyDrawingPanel1.FontName);
  WriteLn(OptFile, 'i FontSize ', MainForm.MyDrawingPanel1.FontSize);
...

function LoadOptions(FName: string): boolean;
begin
...
   if (OptName = 'HostName') and (RecType = 'w') then
        ConnectHostName := OptWord
      else if (OptName = 'FontName') and (RecType = 's') then
        MainForm.MyDrawingPanel1.FontName := OptStr
      else if (OptName = 'FontSize') and (RecType = 'i') then
        MainForm.MyDrawingPanel1.FontSize := OptInt
...
end;

Greetings,

Peter Kiers
0
peterkiers
Asked:
peterkiers
1 Solution
 
TheRealLokiSenior DeveloperCommented:
If you debug "LoadOptions" are you getting the correct value?
can you also put a breakpoint on
  FontDialog1.Font.Name := MyDrawingPanel1.FontName;
and see if fontname is correct there
0
 
peterkiersAuthor Commented:
I found it, i had Font-Dialog property fdFixedPitchOnly set to True.
That's why I couldn't load for example Comic Sans MS or Arial.

Greetings,

Peter kiers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now