I just want a quick and dirty non-modal, non-closable screen that pops up and goes away to make 2 seconds seem more like... 1 second. Using 3-5 lines of code.
Is this too much to ask?
I just want a quick and dirty non-modal, non-closable screen that pops up and goes away to make 2 seconds seem more like... 1 second. Using 3-5 lines of code.
Is this too much to ask?
I generally have a TPanel with a 'Please wait' caption centered on my form, on top of everything, with Visibe set to false. When I start a job, I set Visible to true (optionally calling update to be sure it gets drawn), and to false afterwards (ideally in a finally clause).
If the code that does the work allows for some code to get run inbetween, you could start by timing for a second (or some other intercal) and only then set Visible to true, optionally updating process information and calling the form's Update to be sure the changes get drawn to the screen.
I show a hint for a quick message, sth. like this:
I think that's too much to ask. There's no "magic." Having a window come up with specific attributes takes a lot of information to describe those specific attributes, and that has to come from somewhere. Giving it specific behavior means code that has to come from somewhere too. The VCL makes it a lot easier, but you still need to set up the form.
I'd just set up a form of the right size in the Form Designer. Give it a BorderStyle of bsNone, and you get no close box. (But no border either. Or you can make it bsDialog and give it an OnCloseQuery event that always sets CanClose to false.) Give it a TLabel that says "Please Wait," and a TTimer that calls Self.Release after 2 seconds.
Not very Code-Golf-ish, but it'll work and it's simple to set up.
I usually add a form to the project, like this:
dfm:
while unit looks like this:
you call it like this:
just an idea, refinements is up to you.
If you want to do everything programmatically (that is, if you do not want to design your form in the Delphi form designer), than you can write
in a new unit. Then you can always call these functions like this:
If your application is doing work and not processing any messages during this brief period, you can just do
where
Form4
is the "please wait" form (which isfsStayOnTop
), andSleep(2000)
symbolizes the work done.Now, the best way to do things is in the background (maybe in a separate thread), or at least you should
ProcessMessages
once in a while in slow process. If you do the latter, the equivalent ofSleep(2000)
will still not return until the process is complete, but you need to writein the "please wait" dialog so it cannot be closed (not even with Alt+F4).
If you are using threads or something else more sophisticated, I think that I'll need more details in order to provide an appropriate answer.