Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now