?
Solved

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

Posted on 2007-04-06
7
Medium Priority
?
172 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 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

Independent Software Vendors: 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

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

764 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