procedure RegisterUserCallback(CallBack : TPortCallback);
TPortCallback = procedure(
CP : TObject; Opening : Boolean) of object;
Registers a component that uses TApxComPort.
This method is primarily for internal use. It registers CallBack, a TPortCallback method, as a user of this TApxComPort. When the TApxComPort component opens or closes the physical serial port, it calls all registered TPortCallback routines, passing True for Opening if the port is being opened,False if the port is being closed. CP contains the TApxComPort component issuing the callback.
Due to the layered architecture of Async Professional CLX, this is sometimes essential for its components (TApxModem, for example). It's rarely necessary for your components if they use only the documented TApxComPort properties and methods.
Caution: The registered callback must be thread-safe since it may be executed by more than one of Async Professional CLX's dispatcher threads.
The following example shows an object, TPortUser, that performs work when the serial port is opened or closed. RegisterUserCallback is called from the Whatever method to register the callback method. PortOpenClose is called when the port is opened or closed to perform TPortUser opening and closing activities. When the callback is no longer needed, the SomethingElse method is called to deregister it.
type
TPortUser = class(TComponent)
procedure PortOpenClose(CP : TObject; Opened : Boolean);
end;
var
PortUser : TPortUser;
...
procedure TPortUser.PortOpenClose(
CP : TObject; Opened : Boolean);
begin
if Opened then
... perform opening actions
else
... perform closing actions
end;
procedure TForm1.Whatever(Sender : TObject);
begin
ApxComPort1.RegisterUserCallback(PortUser.PortOpenClose);
...
end;
procedure TForm1.SomethingElse(Sender : TObject);
begin
ApxComPort1.DeregisterUserCallback(PortUser.PortOpenClose);
...
end;
See also: DeregisterUserCallback