Solved

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

Posted on 2007-03-21
3
338 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:
ciuly 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

19 Experts available now in Live!

Get 1:1 Help Now