Solved

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

Posted on 2007-04-06
7
166 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:tiggermark
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry for delay in closing this question
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

9 Experts available now in Live!

Get 1:1 Help Now