Solved

How to :=show all form objects that have a visible property

Posted on 2007-04-06
7
169 Views
Last Modified: 2010-08-05
Where user data entry is unwanted on my data entry form, some objects are :=hide on form.activate.
Some (but not all) of these objects are :=show during the course of data entry.
When a record is saved, the form needs all controls with entry to be cleared.
I have a simple recursive procedure to do this, but an exception occurs when a hidden control is encountered.
How do I write a simple procedure to :=show every control on the form that has a visible property?

Help for my addled brain would be appreciated!
0
Comment
Question by:tiggermark
[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
  • 3
7 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 18864781
You need something like this.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Iterate(Form1);
end;

procedure TForm1.Iterate(Contr: TWinControl);
var
  i: integer;
begin
  for i := 0 to Contr.ControlCount-1 do
    begin
    Contr.Controls[i].Visible := True;
    if Contr.Controls[i] is TWinControl then
      Iterate(Contr.Controls[i] as TWinControl);
    end;
end;

0
 

Author Comment

by:tiggermark
ID: 18865495
Thanks mokule. That does the job elegantly.

Just a minor irritant to fix (for a few more points):
How can I ensure that focus is restored to the control that had it  before the iterate procedure was run?
0
 
LVL 17

Expert Comment

by:mokule
ID: 18867278
I think that showing some controls shouldn't change focus.
However if You would like to be 100% sure You can do it like this.

procedure TForm1.ShowAllControls;
var
  OldControl: TWinControl;
begin
  OldControl := ActiveControl;
  Iterate(Form1);
  ActiveControl := OldControl;
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tiggermark
ID: 18887882
Hi mokule,

There is a problem with your iterate procedure that I have failed to resolve.
I used it to show all controls on a form with a pagecontrol having three tabsheets.

Before the procedure ran, tabsheet1 was selected and its controls visible.
After the procedure ran, tabsheet1 was still selected but the controls of tabsheet3 were visible!
The user has to click on any tab other than that of tabsheet1, then click tabsheet1's tab to view tabsheet1's controls.

I can't make sense of this. Nor have I found a way of using pagecontrol.activepage:=tabsheet1 to help.

I am away for the next 10 days but hope to get back to this then.

tiggermark
0
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 18888042
Well, it looks like some bug in Delphi rather.
I didn't investigate farther what the problem nature.
In any case the code below solves the problem.
Maybe You need to change it a little to be something more adequate for Your application.

 
procedure TForm1.FormShow(Sender: TObject);
begin
   PageControl1.ActivePage := TabSheet2;
   PageControl1.ActivePage := TabSheet1;
end;
0
 
LVL 4

Assisted Solution

by:spk2000ar
spk2000ar earned 25 total points
ID: 19113259
All TWinControls has Showing property (read only). You can test it to ask if any control if shown and then if so, clear it.
0
 

Author Closing Comment

by:tiggermark
ID: 31407186
Sorry for delay in closing this question
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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