Files
MycLib/Src/Myc.Signals.FMX.pas
T
Michael Schimmel 2c56f6e750 Data file handling
2025-06-15 17:29:56 +02:00

64 lines
1.2 KiB
ObjectPascal

unit Myc.Signals.FMX;
interface
uses
System.Classes,
FMX.Controls,
Myc.Signals;
type
TFMXSignalLink = class(TComponent, TSignal.ISubscriber)
private
[volatile]
FInvalidated: Integer;
procedure InvalidateControl;
protected
function Notify: Boolean;
public
constructor Create(AOwner: TControl); reintroduce;
destructor Destroy; override;
function Reset: Boolean;
end;
implementation
uses
System.SyncObjs;
{ TFMXSignalLink }
constructor TFMXSignalLink.Create(AOwner: TControl);
begin
inherited Create(AOwner);
FInvalidated := 0;
end;
destructor TFMXSignalLink.Destroy;
begin
TThread.RemoveQueuedEvents(InvalidateControl);
inherited;
end;
procedure TFMXSignalLink.InvalidateControl;
begin
with TControl(Owner) do
InvalidateRect(LocalRect);
end;
function TFMXSignalLink.Notify: Boolean;
begin
if TInterlocked.Exchange(FInvalidated, 1) = 0 then
TThread.Queue(nil, InvalidateControl);
exit( true );
end;
function TFMXSignalLink.Reset: Boolean;
begin
Result := TInterlocked.Exchange(FInvalidated, 0) > 0;
end;
end.