I'm writing a class that manages a (tape) drive with Winapi. A boolean into the class tells if the (handle of the) drive is opened. All class methods that access to the drive (through open
and close
methods) set this boolean to true and back to false, when they finish.
TTapeDrive = class
private
_isOpened: boolean;
procedure open();
procedure close();
...
end;
I want to display on my VCL form the status of the drive. My first idea was to add an event procedure(isOpened: boolean) of object;
to the class and triggering this event into the open/close methods.
Now, when the user want to perform from the GUI a time-consuming operation on the drive (like rewinding), I execute this action on another thread. So, when the event is triggered by the open/close methods, it is called from another thread respect to the GUI. This is bad, if I want my event handlers to show on the main form the status of the drive.
Moral of the story: I think this is quite a common problem, for a novice, so... how can I solve this problem?
The only solution that comes to me is to add an event handler to the GUI and passing this to the other thread, but it seems to me quite a poor solution...