DataPoint

This commit is contained in:
Michael Schimmel
2025-06-24 08:11:46 +02:00
parent 6c7cc2569b
commit a3da63ad6a
14 changed files with 902 additions and 633 deletions
+19 -17
View File
@@ -5,23 +5,25 @@ interface
uses
System.Classes,
System.SysUtils,
System.Messaging,
FMX.Controls,
Myc.Signals;
type
TFMXValidationState = class(TComponent, TSignal.ISubscriber)
TFMXValidationState = class(TComponent)
private
[volatile]
FInvalidated: Integer;
FSignal: TSignal.ISignal;
FSubscription: TSignal.TSubscriptionTag;
FSignal: TSignal;
FInvalidated: TFlag;
FSubscription: TSignal.TSubscription;
FProc: TProc;
procedure CallProc;
FIdleSubsription: TMessageSubscriptionId;
procedure DoIdle(const Sender: TObject; const M: TMessage);
protected
function Notify: Boolean;
public
constructor Create(AOwner: TControl; const ASignal: TSignal.ISignal; const AProc: TProc); reintroduce;
constructor Create(AOwner: TControl; const ASignal: TSignal; const AProc: TProc); reintroduce;
destructor Destroy; override;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
@@ -30,47 +32,47 @@ type
implementation
uses
System.SyncObjs;
System.SyncObjs,
FMX.Types;
{ TFMXValidationState }
constructor TFMXValidationState.Create(AOwner: TControl; const ASignal: TSignal.ISignal; const AProc: TProc);
constructor TFMXValidationState.Create(AOwner: TControl; const ASignal: TSignal; const AProc: TProc);
begin
inherited Create(AOwner);
FInvalidated := 0;
FSignal := ASignal;
FInvalidated := TFlag.CreateFlag;
FProc := AProc;
end;
destructor TFMXValidationState.Destroy;
begin
TThread.RemoveQueuedEvents(CallProc);
inherited;
end;
procedure TFMXValidationState.AfterConstruction;
begin
inherited;
FSubscription := FSignal.Subscribe(Self);
FSubscription := FSignal.Subscribe(FInvalidated);
FIdleSubsription := TMessageManager.DefaultManager.SubscribeToMessage(TIdleMessage, DoIdle);
end;
procedure TFMXValidationState.BeforeDestruction;
begin
FSignal.Unsubscribe(FSubscription);
TMessageManager.DefaultManager.Unsubscribe(TIdleMessage, FIdleSubsription);
FSubscription.Unsubscribe;
inherited;
end;
procedure TFMXValidationState.CallProc;
procedure TFMXValidationState.DoIdle(const Sender: TObject; const M: TMessage);
begin
if TInterlocked.Exchange(FInvalidated, 0) > 0 then
if FInvalidated.Reset then
FProc;
end;
function TFMXValidationState.Notify: Boolean;
begin
if TInterlocked.Exchange(FInvalidated, 1) = 0 then
TThread.Queue(nil, CallProc);
exit(true);
Result := FInvalidated.Notify;
end;
end.