Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Manually cancelling a Command (http://www.chiefdelphi.com/forums/showthread.php?t=146155)

axiomofdarkness 23-03-2016 14:43

Manually cancelling a Command
 
Hello,

I am trying to create a Command subclass which listens for an interrupt to cancel the command. When cancelling the command, I have tried using the Cancel() method, but it fails when the command is part of a CommandGroup. Is there a universal way to forcibly end a command from within the command itself?

EDIT: Also, can the Cancel() method be used on a CommandGroup object? If so, I could work around this issue.

euhlmann 23-03-2016 14:56

Re: Manually cancelling a Command
 
Within your command:

Code:

if(getGroup() != null) getGroup().cancel();
else cancel();


notmattlythgoe 23-03-2016 14:57

Re: Manually cancelling a Command
 
Quote:

Originally Posted by axiomofdarkness (Post 1561955)
Hello,

I am trying to create a Command subclass which listens for an interrupt to cancel the command. When cancelling the command, I have tried using the Cancel() method, but it fails when the command is part of a CommandGroup. Is there a universal way to forcibly end a command from within the command itself?

EDIT: Also, can the Cancel() method be used on a CommandGroup object? If so, I could work around this issue.

What about listening for the interrupt and setting a variable that will finish the command during the next iteration?

axiomofdarkness 23-03-2016 15:27

Re: Manually cancelling a Command
 
Quote:

Originally Posted by euhlmann (Post 1561964)
Within your command:

Code:

if(getGroup() != null) getGroup().cancel();
else cancel();


Will this cause issues if multiple commands are trying to end their parent CommandGroup?

Ether 23-03-2016 15:29

Re: Manually cancelling a Command
 
Quote:

Originally Posted by notmattlythgoe (Post 1561965)
What about listening for the interrupt

Hmm. What does it mean to "listen" for an interrupt?



axiomofdarkness 23-03-2016 15:48

Re: Manually cancelling a Command
 
Quote:

Originally Posted by Ether (Post 1562001)
Hmm. What does it mean to "listen" for an interrupt?

I have a background thread that checks for a certain button combination on the joystick being pressed. The Cancel() method will be called when that condition is true.

Ether 23-03-2016 15:53

Re: Manually cancelling a Command
 
Quote:

Originally Posted by axiomofdarkness (Post 1562019)
I have a background thread that checks for a certain button combination on the joystick being pressed.

That's polling, not an interrupt.



axiomofdarkness 23-03-2016 16:38

Re: Manually cancelling a Command
 
Quote:

Originally Posted by Ether (Post 1562022)
That's polling, not an interrupt.

My mistake - I apologize for the error. What would an interrupt be then?

Ether 23-03-2016 17:05

Re: Manually cancelling a Command
 
Quote:

Originally Posted by axiomofdarkness (Post 1562063)
What would an interrupt be then?

The hardware generates an electrical signal (called an interrupt) that causes the CPU to stop what it's doing, save its "context", jump to a new location in program memory, and start executing there. That location is called an ISR -- interrupt service routine. When the ISR is done executing, it tells the CPU to go back to where it was when the interrupt occurred. The CPU uses the saved "context" to go back to where it was, as it was.

You can see there is no polling involved. That's the advantage of interrupts.

The disadvantage is that interrupts can occur at any time -- asynchronously -- so you have to be careful when using them.




All times are GMT -5. The time now is 11:01.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi