Solved

Iterating through controls within a control. Is there a way to make one call for all forms?

Posted on 2007-03-21
3
346 Views
Last Modified: 2010-04-05
I have the following two procedures to change the fonts if DPI setting is not 96. As it is I would need to call the procedure in the  formshow event of every form for it to take effect for every form. Is there a way to make the call to the procedure in one place where it will be executed for all forms if the DPI setting is not 96.

procedure TSLCCOTForm.FormShow(Sender: TObject);
begin
  if PixelsPerInch <> 96 then
  MainForm.Iterate(SLCCOTForm);
end;

procedure TMainForm.Iterate(Contr: TWinControl);
var
i, DesiredSize : integer;
begin
  for i := 0 to Contr.ControlCount -1 do
    begin
       DesiredSize := 10;
       TFooClass(Contr.Controls[i]).Font.Name := 'Arial';
       TFooClass(Contr.Controls[i]).Font.Size := MulDiv(DesiredSize,96,PixelsPerInch);
       if Contr.Controls[i] is TWinControl then
       Iterate(Contr.Controls[i] as TWinControl);
    end;
end;
0
Comment
Question by:QurbanDurrani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 300 total points
ID: 18769773
if there is no other code in the formshow event of the rest of the forms, then yes, it's simple (otherwise, you need to save the old formshow and call it yourself).

modify the dpr and after all the form creates, do this:

  for i:=1 to application.ComponentCount do
    if (application.Components[i-1] is TForm) and (application.Components[i-1]<>application.MainForm) then
      (application.Components[i-1] as TForm).OnShow:=application.MainForm.OnShow;

move the
procedure TSLCCOTForm.FormShow(Sender: TObject);
to the
procedure TMainForm.FormShow(Sender: TObject);

and change the body from
  if PixelsPerInch <> 96 then
  MainForm.Iterate(SLCCOTForm);
to
  if PixelsPerInch <> 96 then
  MainForm.Iterate(sender);

you might also want to read this: http://delphi.about.com/od/standards/a/aa030700a.htm
0
 
LVL 3

Assisted Solution

by:jpedef
jpedef earned 200 total points
ID: 18769866
I had similar problem and it was solved by creating a common base form. Base form sets fonts in its AfterConstruction procedure.

  TCustomBaseForm = class(TForm)
  protected
    procedure Iterate(Contr: TWinControl);
  public
    procedure AfterConstruction; override;
  end;

procedure TPaCustomForm.AfterConstruction;
begin
  inherited;
  if PixelsPerInch <> 96 then
    Iterate(self);
end;

Forms in application are declared as

  TMyForm = class(TCustomBaseForm)
  ...
  end;
0
 

Author Comment

by:QurbanDurrani
ID: 18772800
Thanks guys.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question