AuraTrader Sample

This commit is contained in:
Michael Schimmel
2025-06-17 21:49:09 +02:00
parent f81337c98d
commit a9aff8c41a
13 changed files with 2093 additions and 306 deletions
+33 -20
View File
@@ -4,23 +4,27 @@ interface
uses
System.Classes,
System.SysUtils,
FMX.Controls,
Myc.Signals;
type
TFMXSignalLink = class(TComponent, TSignal.ISubscriber)
TFMXValidationState = class(TComponent, TSignal.ISubscriber)
private
[volatile]
FInvalidated: Integer;
procedure InvalidateControl;
FSignal: TSignal.ISignal;
FSubscription: TSignal.TSubscriptionTag;
FProc: TProc;
procedure CallProc;
protected
function Notify: Boolean;
public
constructor Create(AOwner: TControl); reintroduce;
constructor Create(AOwner: TControl; const ASignal: TSignal.ISignal; const AProc: TProc); reintroduce;
destructor Destroy; override;
function Reset: Boolean;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
end;
implementation
@@ -28,36 +32,45 @@ implementation
uses
System.SyncObjs;
{ TFMXSignalLink }
{ TFMXValidationState }
constructor TFMXSignalLink.Create(AOwner: TControl);
constructor TFMXValidationState.Create(AOwner: TControl; const ASignal: TSignal.ISignal; const AProc: TProc);
begin
inherited Create(AOwner);
FInvalidated := 0;
FSignal := ASignal;
FProc := AProc;
end;
destructor TFMXSignalLink.Destroy;
destructor TFMXValidationState.Destroy;
begin
TThread.RemoveQueuedEvents(InvalidateControl);
TThread.RemoveQueuedEvents(CallProc);
inherited;
end;
procedure TFMXSignalLink.InvalidateControl;
procedure TFMXValidationState.AfterConstruction;
begin
with TControl(Owner) do
InvalidateRect(LocalRect);
inherited;
FSubscription := FSignal.Subscribe(Self);
end;
function TFMXSignalLink.Notify: Boolean;
procedure TFMXValidationState.BeforeDestruction;
begin
FSignal.Unsubscribe(FSubscription);
inherited;
end;
procedure TFMXValidationState.CallProc;
begin
if TInterlocked.Exchange(FInvalidated, 0) > 0 then
FProc;
end;
function TFMXValidationState.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;
TThread.Queue(nil, CallProc);
exit(true);
end;
end.