Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temporarily locking on-form components - Possible?

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I'm working with a program that requires a vast amount of database work. Originally, this caused the on-screen form to sort of 'freeze' when the program ran; it would end up taking on the appearance of anything that appeared on the screen above it. A poster on this forum recommended the 'application.ProcessMessages' command, which works quite nicely to solve that problem. However, I believe I am running up against another one related to this.

As things stand, my program has some moments where it appears nothing is happening. (The system is getting and processing information from the database, but nothing is showing onscreen.) It is possible that the user could hit another command during this time. I know this; I accidentally did so with the Exit button during such a lull. This caused the program to exit as soon as the run was done, before the retrieved information could be viewed.

If I can do this, I know the end users I'm developing for can. Is there some way to lock (or ignore) clickable components so that I can prevent this (or something similar) from happening to them?
 
The Enable property of components, such as buttons is there for this purpose.

 
another option would be to change the mouse pointer icon to a spinning hourglass until the process has completed letting the user know that something is happening:
Code:
[navy][i]// for automatic syntax highlighting see faq102-6487 
[/i][/navy][b]procedure[/b] TfrmMain.Button1Click(Sender: TObject);
[b]var[/b]
Save_Cursor : TCursor;
[b]begin[/b]
  Save_Cursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  [b]try[/b]
    [COLOR=green][b]YourProcess();[/b][/color]
  [b]finally[/b]
    Screen.Cursor := Save_Cursor;[navy][i]//Always restore to normal
[/i][/navy]  [b]end[/b];
[b]end[/b];


Leslie

In an open world there's no need for windows and gates
 
You could also do something like this:

Have two procedures: EnableControls & DisableControls. DisableControls would set all the buttons to disabled, and EnableControls would reenable the buttons.

Then do something like this:

Code:
procedure TfrmMain.Button1Click(Sender: TObject);
begin
  try
    DisableControls().
    YourProcess();
  finally
    EnableControls();
  end;
end;

You could also combine this with the example LesPaul gave.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top