[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

What is the best way to open a form and make the ado connection after showing the form?

Hello guys,

I would like a clue about process.

I have 10 queries that I need to open when I enter in my form, but first I would like to open the form, show it to user and only after open the queries, because the process is a little bit slow. It takes about 30 seconds.

What event should I write my code?
Onshow and onCreate is not possible, active is gonna make the process again when the form becomes active after losing the focus.

thanks
0
hidrau
Asked:
hidrau
  • 3
  • 2
  • 2
4 Solutions
 
rfwoolfCommented:
OnShow should work because this only occurs once when the form becomes visible or is "shown". OnActive like you say is a problem because if you click on another form and then click back to your form it will trigger that event.

In any event, you could always declare a global variable that ensures the procedure is only run once.
e.g. you could put an invisible edit box saying "UnRun" and after you have run the procedure set it to "Run".

Another thing...
When you're setting your ADO datasets to active you could use DisableControls and EnableControls to make sure that any data-aware controls  become disabled while it is processing.
Tbl3Staff.DisableControls;
(and later)
Tbl4Staff.EnableControls
0
 
JohnjcesCommented:
Add a ttimer to your form. In the OnShow event or even in the oncreate event start your timer. Timer1.Enabled := true;

Then in the ttimer event, your very first line should Timer1.Enabled := False and run your queries.

Set the time in the timer to allow your form to show, etc.

Might be the easiest solution

John
0
 
rfwoolfCommented:
You could also have a progress bar, either based no the timer, or, increment the progress bar based on the number of datasets, e.g. open 1 dataset = 10% done, open 2nd dataset = 20% done
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
hidrauAuthor Commented:
I see,

There should be an event named onaftershow :))

I am gonna test,

What do you think if I put this option in my onpaint, something like this:

If form1.tag = 0 then begin
 form1.tag := 1
 all queries
End
0
 
rfwoolfCommented:
No don't put that on OnPaint!
Just use OnShow (or OnCreate if you want it to start working from the moment your application creates the form, i.e. when it runs).
Then use the tag if you really want.

Take care about Access Violations if you're using OnCreate - if that form that's being created in any way depends on another form that hasn't been created, you may get an access violation.
Example: If your datasets and connections are on a datamodule form, and you trigger your queries on a form called Form5, make sure that the datamodule form is created in your project's list before Form5 is.
0
 
JohnjcesCommented:
Any repainting of the form can cause your queries to run again.

But, try it!

John
0
 
hidrauAuthor Commented:
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now