[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-04-06
7
Medium Priority
?
178 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
  • 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 500 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 100 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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