Solved

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

Posted on 2007-04-06
7
168 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

807 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