stevegill 0 Posted May 18, 2019 I'm using Async and Await with two methods. The CheckForDueRemindersProcess method has two var parameters. The intention is to run this in a thread and receive the values via the parameters. The values are then passed to the CheckForDueReminderFinish method, which updates VCL components. Is the following code the correct way to do this? var RemindersDue: Boolean; RemindersCount: integer; begin Async(procedure begin CheckForDueRemindersProcess(RemindersDue, RemindersCount); end).Await(procedure begin CheckForDueRemindersFinish(RemindersDue, RemindersCount); end); end; Another question: is it ok to declare the variables as shown above in the calling method, or should they be declared like this: Async(procedure var RemindersDue: Boolean; RemindersCount: integer; begin CheckForDueRemindersProcess(RemindersDue, RemindersCount); end).Await(procedure begin CheckForDueRemindersFinish(RemindersDue, RemindersCount); end); Thanks. = Steve Share this post Link to post
Primož Gabrijelčič 223 Posted May 18, 2019 The first approach is OK. The second code fragment would not compile as the anonymous method in Await wouldn't know anything about RemindersDue and RemindersCount. Share this post Link to post
stevegill 0 Posted May 18, 2019 35 minutes ago, Primož Gabrijelčič said: The first approach is OK. The second code fragment would not compile as the anonymous method in Await wouldn't know anything about RemindersDue and RemindersCount. Thanks Primoz. Now that I've taken another look at the second code example it's pretty obvious. In the first code snippet, if I dynamically created and destroyed database components in the Async part of the code, I'm assuming that they would be completely isolated from the main thread. Is that correct? = Steve Share this post Link to post
Primož Gabrijelčič 223 Posted May 18, 2019 43 minutes ago, stevegill said: In the first code snippet, if I dynamically created and destroyed database components in the Async part of the code, I'm assuming that they would be completely isolated from the main thread. Is that correct? Indeed it is. Share this post Link to post
stevegill 0 Posted May 18, 2019 Thanks Primoz! I love the Omnithread library. It makes things a lot easier. = Steve Share this post Link to post