GUI Signals
This commit is contained in:
@@ -26,7 +26,8 @@ type
|
||||
strict private
|
||||
// Head of the linked list. The pointer value itself is repurposed for a spinlock.
|
||||
// Bit 0 of the address stores the lock state (0 = locked, 1 = unlocked).
|
||||
[volatile] FList: PItem;
|
||||
[volatile]
|
||||
FList: PItem;
|
||||
|
||||
// Allocates memory for a new TItem.
|
||||
class function AllocItem: PItem; static; inline;
|
||||
|
||||
@@ -108,9 +108,6 @@ type
|
||||
constructor Create(AInit: Boolean);
|
||||
destructor Destroy; override;
|
||||
|
||||
// Factory method to create a new TMycFlag instance.
|
||||
class function CreateDirty: TFlag.IFlag; static;
|
||||
|
||||
function Subscribe(Subscriber: TSignal.ISubscriber): Pointer;
|
||||
procedure Unsubscribe(Tag: Pointer);
|
||||
|
||||
@@ -402,12 +399,6 @@ begin
|
||||
FSubscribers.Create;
|
||||
end;
|
||||
|
||||
class function TMycFlag.CreateDirty: TFlag.IFlag;
|
||||
begin
|
||||
// Factory method to create a new TMycFlag instance.
|
||||
Result := TMycFlag.Create(true);
|
||||
end;
|
||||
|
||||
destructor TMycFlag.Destroy;
|
||||
begin
|
||||
FSubscribers.Destroy; // Clean up the subscriber list.
|
||||
|
||||
+38
-37
@@ -6,73 +6,74 @@ uses
|
||||
System.Classes,
|
||||
System.SysUtils,
|
||||
System.Messaging,
|
||||
FMX.Controls,
|
||||
Myc.Signals;
|
||||
|
||||
type
|
||||
TFMXValidationState = class(TComponent)
|
||||
TMsgProc = reference to procedure( const Sender: TObject; const M: TMessage );
|
||||
|
||||
TComponentValidation = 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;
|
||||
FReceived: TFlag;
|
||||
FProc: TMsgProc;
|
||||
FSubscription: TMessageSubscriptionId;
|
||||
FMsgClass: TClass;
|
||||
procedure DoMsg(const Sender: TObject; const M: TMessage);
|
||||
|
||||
public
|
||||
constructor Create(AOwner: TControl; const ASignal: TSignal; const AProc: TProc); reintroduce;
|
||||
constructor Create(AOwner: TComponent; const AMsgClass: TClass; const ASignal: TSignal; const AProc: TMsgProc); reintroduce;
|
||||
destructor Destroy; override;
|
||||
procedure AfterConstruction; override;
|
||||
procedure BeforeDestruction; override;
|
||||
end;
|
||||
|
||||
TComponentValidationHelper = class helper for TComponent
|
||||
procedure AddMsgHandler(const MsgClass: TClass; const Signal: TSignal; const Proc: TMsgProc);
|
||||
procedure AddIdleHandler(const Signal: TSignal; const Proc: TProc);
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.SyncObjs,
|
||||
FMX.Types;
|
||||
{$IFDEF FRAMEWORK_FMX}
|
||||
FMX.Types
|
||||
{$ELSE}
|
||||
VCL.Types // to be checked
|
||||
{$IFEND};
|
||||
|
||||
{ TFMXValidationState }
|
||||
{ TComponentValidation }
|
||||
|
||||
constructor TFMXValidationState.Create(AOwner: TControl; const ASignal: TSignal; const AProc: TProc);
|
||||
constructor TComponentValidation.Create(AOwner: TComponent; const AMsgClass: TClass; const ASignal: TSignal; const AProc: TMsgProc);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FSignal := ASignal;
|
||||
FInvalidated := TFlag.CreateFlag;
|
||||
FMsgClass := AMsgClass;
|
||||
FProc := AProc;
|
||||
FReceived := TFlag.CreateObserver(ASignal);
|
||||
FSubscription := TMessageManager.DefaultManager.SubscribeToMessage(FMsgClass, DoMsg);
|
||||
end;
|
||||
|
||||
destructor TFMXValidationState.Destroy;
|
||||
destructor TComponentValidation.Destroy;
|
||||
begin
|
||||
TMessageManager.DefaultManager.Unsubscribe(FMsgClass, FSubscription);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TFMXValidationState.AfterConstruction;
|
||||
procedure TComponentValidation.DoMsg(const Sender: TObject; const M: TMessage);
|
||||
begin
|
||||
inherited;
|
||||
FSubscription := FSignal.Subscribe(FInvalidated);
|
||||
FIdleSubsription := TMessageManager.DefaultManager.SubscribeToMessage(TIdleMessage, DoIdle);
|
||||
if FReceived.Reset then
|
||||
FProc( Sender, M );
|
||||
end;
|
||||
|
||||
procedure TFMXValidationState.BeforeDestruction;
|
||||
procedure TComponentValidationHelper.AddIdleHandler(const Signal: TSignal; const Proc: TProc);
|
||||
begin
|
||||
TMessageManager.DefaultManager.Unsubscribe(TIdleMessage, FIdleSubsription);
|
||||
FSubscription.Unsubscribe;
|
||||
inherited;
|
||||
var capProc := Proc;
|
||||
AddMsgHandler(TIdleMessage, Signal,
|
||||
procedure( const Sender: TObject; const M: TMessage )
|
||||
begin
|
||||
capProc();
|
||||
end );
|
||||
end;
|
||||
|
||||
procedure TFMXValidationState.DoIdle(const Sender: TObject; const M: TMessage);
|
||||
procedure TComponentValidationHelper.AddMsgHandler(const MsgClass: TClass; const Signal: TSignal; const Proc: TMsgProc);
|
||||
begin
|
||||
if FInvalidated.Reset then
|
||||
FProc;
|
||||
end;
|
||||
|
||||
function TFMXValidationState.Notify: Boolean;
|
||||
begin
|
||||
Result := FInvalidated.Notify;
|
||||
TComponentValidation.Create(Self, MsgClass, Signal, Proc);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
@@ -14,7 +14,7 @@ type
|
||||
TChunk = TArray<TDataPoint<T>>;
|
||||
private
|
||||
FChunks: TArray<TChunk>;
|
||||
FChunks1: TArray<TChunk>;
|
||||
FChunks1: TArray<TChunk>;
|
||||
FCount: Int64;
|
||||
FMaxLookback: Int64;
|
||||
FTotalCount: Int64;
|
||||
@@ -40,8 +40,8 @@ type
|
||||
// Null object implementation for IDataSeries<T>
|
||||
TNullDataSeries<T> = class(TInterfacedObject, IDataSeries<T>)
|
||||
strict private
|
||||
class var
|
||||
FNull: IDataSeries<T>;
|
||||
class var
|
||||
FNull: IDataSeries<T>;
|
||||
private
|
||||
class constructor CreateClass;
|
||||
public
|
||||
@@ -173,7 +173,7 @@ end;
|
||||
|
||||
function TDataArray<T>.Copy: IDataSeries<T>;
|
||||
begin
|
||||
Result := TStaticDataSeries<T>.Create( FChunks, FCount, FMaxLookback, FTotalCount );
|
||||
Result := TStaticDataSeries<T>.Create(FChunks, FCount, FMaxLookback, FTotalCount);
|
||||
end;
|
||||
|
||||
function TDataArray<T>.GetCount: Int64;
|
||||
|
||||
Reference in New Issue
Block a user