Files
MycLib/Src/Myc.Signals.FMX.pas
T
Michael Schimmel a3da63ad6a DataPoint
2025-06-24 08:11:46 +02:00

79 lines
1.8 KiB
ObjectPascal

unit Myc.Signals.FMX;
interface
uses
System.Classes,
System.SysUtils,
System.Messaging,
FMX.Controls,
Myc.Signals;
type
TFMXValidationState = class(TComponent)
private
[volatile]
FSignal: TSignal;
FInvalidated: TFlag;
FSubscription: TSignal.TSubscription;
FProc: TProc;
FIdleSubsription: TMessageSubscriptionId;
procedure DoIdle(const Sender: TObject; const M: TMessage);
protected
function Notify: Boolean;
public
constructor Create(AOwner: TControl; const ASignal: TSignal; const AProc: TProc); reintroduce;
destructor Destroy; override;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
end;
implementation
uses
System.SyncObjs,
FMX.Types;
{ TFMXValidationState }
constructor TFMXValidationState.Create(AOwner: TControl; const ASignal: TSignal; const AProc: TProc);
begin
inherited Create(AOwner);
FSignal := ASignal;
FInvalidated := TFlag.CreateFlag;
FProc := AProc;
end;
destructor TFMXValidationState.Destroy;
begin
inherited;
end;
procedure TFMXValidationState.AfterConstruction;
begin
inherited;
FSubscription := FSignal.Subscribe(FInvalidated);
FIdleSubsription := TMessageManager.DefaultManager.SubscribeToMessage(TIdleMessage, DoIdle);
end;
procedure TFMXValidationState.BeforeDestruction;
begin
TMessageManager.DefaultManager.Unsubscribe(TIdleMessage, FIdleSubsription);
FSubscription.Unsubscribe;
inherited;
end;
procedure TFMXValidationState.DoIdle(const Sender: TObject; const M: TMessage);
begin
if FInvalidated.Reset then
FProc;
end;
function TFMXValidationState.Notify: Boolean;
begin
Result := FInvalidated.Notify;
end;
end.