Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-21
3
Medium Priority
?
351 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 1200 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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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