Solved

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

Posted on 2007-03-21
3
347 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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