Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tip: FocusModal #81

Open
delphidabbler opened this issue Nov 19, 2022 · 0 comments
Open

New tip: FocusModal #81

delphidabbler opened this issue Nov 19, 2022 · 0 comments
Assignees
Labels
considering Considering or investigating the issue enhancement New feature or request

Comments

@delphidabbler
Copy link
Owner

delphidabbler commented Nov 19, 2022

Possible new tip from extra/Topelina Tips.odt


FocusModal

Open a modal progress window while loading your data.

Question/Problem/Abstract:

Have you ever needed a small window with a progressbar with focus, but having the code being executed in another window?

I use this trick for our client/server application when retrieving data from the server.

The connection is uninterruptable, and the user is not allowed to click anywhere while the connection is open. This small trick prohibits that, and tells the user about the process of retrieving his data.

The recipe is like this:

Create a small sized window with a TProgressBar inside. Name the TProgressBar "ProgressBar".

Make an instance of the window. For example:

var 
  f : TfrmProgress; 

initialization 
  f := nil; 
end.

To open the window, use the following lines of code:

procedure OpenWindow; 
begin 
  if f = nil then 
  begin 
    f := TfrmProgress.Create( Application ); 
    f.WindowList := DisableTaskWindows(f.Handle); 
    f.Show; 
  end; 
end; 

The window is now open and modal, but your thread of code continues where you left off.

You can set the progressbar by:

procedure SetProgressBar( APosition : integer ); 
begin 
  if f <> nil then 
    f.ProgressBar.Position := APosition; 
end; 

To close the window, do the following:

procedure CloseWindow; 
begin 
  if f <> nil then 
  begin 
    EnableTaskWindows(f.WindowList); 
    f.Close; 
    f.Free; 
    f := nil; 
  end; 
end; 

Usage:

Use the code like this:

begin 
  OpenWindow; 
  SetProgressBar( 33 ); 
  do_something; 
  SetProgressBar( 66 ); // Increase the progressbar to indicate 
                        // progress 
  do_something_else; 
  SetProgressBar( 100 ); 
  CloseWindow; 
end;

Contributed by: topellina [email protected]

@delphidabbler delphidabbler changed the title New FocusModal tip New tip: FocusModal Nov 19, 2022
@delphidabbler delphidabbler self-assigned this Jun 18, 2023
@delphidabbler delphidabbler added enhancement New feature or request considering Considering or investigating the issue labels Jun 18, 2023
@delphidabbler delphidabbler moved this from Accepted to Considering in Delphi Tips Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
considering Considering or investigating the issue enhancement New feature or request
Projects
Status: Considering
Development

No branches or pull requests

1 participant