Minor fixes to GUIContext
This commit is contained in:
parent
4a287a0715
commit
b2e6510d19
@ -13,6 +13,7 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
|
|||||||
Font.Name = 'Tahoma'
|
Font.Name = 'Tahoma'
|
||||||
Font.Style = []
|
Font.Style = []
|
||||||
OldCreateOrder = False
|
OldCreateOrder = False
|
||||||
|
Position = poScreenCenter
|
||||||
OnCloseQuery = FormCloseQuery
|
OnCloseQuery = FormCloseQuery
|
||||||
DesignSize = (
|
DesignSize = (
|
||||||
285
|
285
|
||||||
@ -27,7 +28,7 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
|
|||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akLeft, akBottom]
|
||||||
Caption = '&Close'
|
Caption = '&Close'
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
ExplicitTop = 180
|
OnClick = btnCloseClick
|
||||||
end
|
end
|
||||||
object gbStatus: TGroupBox
|
object gbStatus: TGroupBox
|
||||||
AlignWithMargins = True
|
AlignWithMargins = True
|
||||||
@ -42,7 +43,6 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
|
|||||||
Align = alTop
|
Align = alTop
|
||||||
Caption = ' Status '
|
Caption = ' Status '
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
ExplicitWidth = 261
|
|
||||||
object lblStatus: TLabel
|
object lblStatus: TLabel
|
||||||
Left = 34
|
Left = 34
|
||||||
Top = 26
|
Top = 26
|
||||||
@ -50,11 +50,13 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
|
|||||||
Height = 13
|
Height = 13
|
||||||
Caption = 'Starting...'
|
Caption = 'Starting...'
|
||||||
end
|
end
|
||||||
object Shape1: TShape
|
object shpStatus: TShape
|
||||||
Left = 12
|
Left = 12
|
||||||
Top = 24
|
Top = 24
|
||||||
Width = 16
|
Width = 16
|
||||||
Height = 16
|
Height = 16
|
||||||
|
Brush.Color = 33023
|
||||||
|
Shape = stCircle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
object gbCustomControl: TGroupBox
|
object gbCustomControl: TGroupBox
|
||||||
@ -89,7 +91,6 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
|
|||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
Text = '128'
|
Text = '128'
|
||||||
OnChange = edtControlCodeChange
|
OnChange = edtControlCodeChange
|
||||||
ExplicitWidth = 173
|
|
||||||
end
|
end
|
||||||
object btnSend: TButton
|
object btnSend: TButton
|
||||||
Left = 180
|
Left = 180
|
||||||
@ -99,7 +100,7 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
|
|||||||
Anchors = [akTop, akRight]
|
Anchors = [akTop, akRight]
|
||||||
Caption = '&Send'
|
Caption = '&Send'
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
ExplicitLeft = 251
|
OnClick = btnSendClick
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,14 +20,16 @@ type
|
|||||||
btnClose: TButton;
|
btnClose: TButton;
|
||||||
gbStatus: TGroupBox;
|
gbStatus: TGroupBox;
|
||||||
lblStatus: TLabel;
|
lblStatus: TLabel;
|
||||||
Shape1: TShape;
|
shpStatus: TShape;
|
||||||
gbCustomControl: TGroupBox;
|
gbCustomControl: TGroupBox;
|
||||||
lblControlCode: TLabel;
|
lblControlCode: TLabel;
|
||||||
edtControlCode: TEdit;
|
edtControlCode: TEdit;
|
||||||
btnSend: TButton;
|
btnSend: TButton;
|
||||||
|
|
||||||
procedure edtControlCodeChange(Sender: TObject);
|
|
||||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||||
|
procedure edtControlCodeChange(Sender: TObject);
|
||||||
|
procedure btnSendClick(Sender: TObject);
|
||||||
|
procedure btnCloseClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
FContext: IX2ServiceContext;
|
FContext: IX2ServiceContext;
|
||||||
FService: IX2Service;
|
FService: IX2Service;
|
||||||
@ -35,6 +37,8 @@ type
|
|||||||
procedure DoShow; override;
|
procedure DoShow; override;
|
||||||
|
|
||||||
procedure CMAfterShow(var Msg: TMessage); message CM_AFTERSHOW;
|
procedure CMAfterShow(var Msg: TMessage); message CM_AFTERSHOW;
|
||||||
|
|
||||||
|
function GetControlCode: Byte;
|
||||||
public
|
public
|
||||||
property Context: IX2ServiceContext read FContext write FContext;
|
property Context: IX2ServiceContext read FContext write FContext;
|
||||||
property Service: IX2Service read FService write FService;
|
property Service: IX2Service read FService write FService;
|
||||||
@ -45,12 +49,20 @@ implementation
|
|||||||
uses
|
uses
|
||||||
System.Math,
|
System.Math,
|
||||||
System.SysUtils,
|
System.SysUtils,
|
||||||
|
Vcl.Graphics,
|
||||||
Winapi.Windows;
|
Winapi.Windows;
|
||||||
|
|
||||||
|
|
||||||
{$R *.dfm}
|
{$R *.dfm}
|
||||||
|
|
||||||
|
|
||||||
|
const
|
||||||
|
StatusColorStarting = $00B0FFB0;
|
||||||
|
StatusColorStarted = clGreen;
|
||||||
|
StatusColorStopping = $008080FF;
|
||||||
|
StatusColorStopped = clRed;
|
||||||
|
|
||||||
|
|
||||||
// #ToDo1 -oMvR: 21-10-2016: separate service handling out to thread to prevent blocking of the UI
|
// #ToDo1 -oMvR: 21-10-2016: separate service handling out to thread to prevent blocking of the UI
|
||||||
|
|
||||||
|
|
||||||
@ -65,26 +77,45 @@ end;
|
|||||||
|
|
||||||
procedure TX2ServiceContextGUIForm.CMAfterShow(var Msg: TMessage);
|
procedure TX2ServiceContextGUIForm.CMAfterShow(var Msg: TMessage);
|
||||||
begin
|
begin
|
||||||
|
shpStatus.Brush.Color := StatusColorStarting;
|
||||||
lblStatus.Caption := 'Starting...';
|
lblStatus.Caption := 'Starting...';
|
||||||
lblStatus.Update;
|
Application.ProcessMessages;
|
||||||
|
|
||||||
if Service.Start(Context) then
|
if Service.Start(Context) then
|
||||||
lblStatus.Caption := 'Started'
|
begin
|
||||||
else
|
shpStatus.Brush.Color := StatusColorStarted;
|
||||||
|
lblStatus.Caption := 'Started';
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
shpStatus.Brush.Color := StatusColorStopped;
|
||||||
lblStatus.Caption := 'Failed to start';
|
lblStatus.Caption := 'Failed to start';
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TX2ServiceContextGUIForm.edtControlCodeChange(Sender: TObject);
|
procedure TX2ServiceContextGUIForm.edtControlCodeChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
edtControlCode.Text := IntToStr(Min(Max(StrToIntDef(edtControlCode.Text, 0), 128), 255));
|
edtControlCode.Text := IntToStr(GetControlCode);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TX2ServiceContextGUIForm.btnSendClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Service.DoCustomControl(GetControlCode);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TX2ServiceContextGUIForm.btnCloseClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Close;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TX2ServiceContextGUIForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
procedure TX2ServiceContextGUIForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||||
begin
|
begin
|
||||||
|
shpStatus.Brush.Color := StatusColorStopping;
|
||||||
lblStatus.Caption := 'Stopping...';
|
lblStatus.Caption := 'Stopping...';
|
||||||
lblStatus.Update;
|
Application.ProcessMessages;
|
||||||
|
|
||||||
CanClose := Service.Stop;
|
CanClose := Service.Stop;
|
||||||
|
|
||||||
@ -92,4 +123,10 @@ begin
|
|||||||
lblStatus.Caption := 'Failed to stop';
|
lblStatus.Caption := 'Failed to stop';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TX2ServiceContextGUIForm.GetControlCode: Byte;
|
||||||
|
begin
|
||||||
|
Result := Byte(Min(Max(StrToIntDef(edtControlCode.Text, 0), 128), 255));
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -26,6 +26,8 @@ uses
|
|||||||
constructor TX2ServiceContextGUI.Create(AService: IX2Service);
|
constructor TX2ServiceContextGUI.Create(AService: IX2Service);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
|
StartService(AService);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,12 +65,14 @@ implementation
|
|||||||
function TX2CustomService.Start(AContext: IX2ServiceContext): Boolean;
|
function TX2CustomService.Start(AContext: IX2ServiceContext): Boolean;
|
||||||
begin
|
begin
|
||||||
FContext := AContext;
|
FContext := AContext;
|
||||||
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TX2CustomService.Stop: Boolean;
|
function TX2CustomService.Stop: Boolean;
|
||||||
begin
|
begin
|
||||||
FContext := nil;
|
FContext := nil;
|
||||||
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user