1
0
mirror of synced 2024-09-19 09:46:09 +00:00

Added X2UtService to DXE2 package

Added support for listing supported custom control codes in the interactive GUI
This commit is contained in:
Mark van Renswoude 2016-10-26 12:30:26 +02:00
parent 360f06ae74
commit d895950bd6
6 changed files with 118 additions and 14 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
__history/ __history/
*.local
*.identcache

View File

@ -60,6 +60,11 @@ contains
X2UtPersistXMLBinding in '..\..\X2UtPersistXMLBinding.pas', X2UtPersistXMLBinding in '..\..\X2UtPersistXMLBinding.pas',
XMLDataBindingUtils in '..\..\XMLDataBindingUtils.pas', XMLDataBindingUtils in '..\..\XMLDataBindingUtils.pas',
X2UtDelphiCompatibility in '..\..\X2UtDelphiCompatibility.pas', X2UtDelphiCompatibility in '..\..\X2UtDelphiCompatibility.pas',
X2UtCursors in '..\..\X2UtCursors.pas'; X2UtCursors in '..\..\X2UtCursors.pas',
X2UtService.GUIContext.Form in '..\..\X2UtService.GUIContext.Form.pas' {X2ServiceContextGUIForm},
X2UtService.GUIContext in '..\..\X2UtService.GUIContext.pas',
X2UtService.Intf in '..\..\X2UtService.Intf.pas',
X2UtService in '..\..\X2UtService.pas',
X2UtService.ServiceContext in '..\..\X2UtService.ServiceContext.pas';
end. end.

View File

@ -206,6 +206,13 @@
<DCCReference Include="..\..\XMLDataBindingUtils.pas"/> <DCCReference Include="..\..\XMLDataBindingUtils.pas"/>
<DCCReference Include="..\..\X2UtDelphiCompatibility.pas"/> <DCCReference Include="..\..\X2UtDelphiCompatibility.pas"/>
<DCCReference Include="..\..\X2UtCursors.pas"/> <DCCReference Include="..\..\X2UtCursors.pas"/>
<DCCReference Include="..\..\X2UtService.GUIContext.Form.pas">
<Form>X2ServiceContextGUIForm</Form>
</DCCReference>
<DCCReference Include="..\..\X2UtService.GUIContext.pas"/>
<DCCReference Include="..\..\X2UtService.Intf.pas"/>
<DCCReference Include="..\..\X2UtService.pas"/>
<DCCReference Include="..\..\X2UtService.ServiceContext.pas"/>
<BuildConfiguration Include="Debug"> <BuildConfiguration Include="Debug">
<Key>Cfg_2</Key> <Key>Cfg_2</Key>
<CfgParent>Base</CfgParent> <CfgParent>Base</CfgParent>

View File

@ -4,8 +4,8 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
BorderIcons = [biSystemMenu, biMinimize] BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle BorderStyle = bsSingle
Caption = 'X2ServiceContextGUIForm' Caption = 'X2ServiceContextGUIForm'
ClientHeight = 177 ClientHeight = 204
ClientWidth = 285 ClientWidth = 439
Color = clBtnFace Color = clBtnFace
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText Font.Color = clWindowText
@ -15,14 +15,15 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
OldCreateOrder = False OldCreateOrder = False
Position = poScreenCenter Position = poScreenCenter
OnCloseQuery = FormCloseQuery OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
DesignSize = ( DesignSize = (
285 439
177) 204)
PixelsPerInch = 96 PixelsPerInch = 96
TextHeight = 13 TextHeight = 13
object btnClose: TButton object btnClose: TButton
Left = 107 Left = 8
Top = 144 Top = 171
Width = 75 Width = 75
Height = 25 Height = 25
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
@ -34,7 +35,7 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
AlignWithMargins = True AlignWithMargins = True
Left = 8 Left = 8
Top = 8 Top = 8
Width = 269 Width = 423
Height = 57 Height = 57
Margins.Left = 8 Margins.Left = 8
Margins.Top = 8 Margins.Top = 8
@ -43,6 +44,7 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
Align = alTop Align = alTop
Caption = ' Status ' Caption = ' Status '
TabOrder = 1 TabOrder = 1
ExplicitWidth = 358
object lblStatus: TLabel object lblStatus: TLabel
Left = 34 Left = 34
Top = 26 Top = 26
@ -63,8 +65,8 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
AlignWithMargins = True AlignWithMargins = True
Left = 8 Left = 8
Top = 73 Top = 73
Width = 269 Width = 423
Height = 60 Height = 88
Margins.Left = 8 Margins.Left = 8
Margins.Top = 8 Margins.Top = 8
Margins.Right = 8 Margins.Right = 8
@ -72,9 +74,10 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
Align = alTop Align = alTop
Caption = ' Custom control ' Caption = ' Custom control '
TabOrder = 2 TabOrder = 2
ExplicitWidth = 358
DesignSize = ( DesignSize = (
269 423
60) 88)
object lblControlCode: TLabel object lblControlCode: TLabel
Left = 12 Left = 12
Top = 27 Top = 27
@ -85,15 +88,16 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
object edtControlCode: TEdit object edtControlCode: TEdit
Left = 72 Left = 72
Top = 24 Top = 24
Width = 102 Width = 256
Height = 21 Height = 21
Anchors = [akLeft, akTop, akRight] Anchors = [akLeft, akTop, akRight]
TabOrder = 0 TabOrder = 0
Text = '128' Text = '128'
OnChange = edtControlCodeChange OnChange = edtControlCodeChange
ExplicitWidth = 191
end end
object btnSend: TButton object btnSend: TButton
Left = 180 Left = 334
Top = 24 Top = 24
Width = 75 Width = 75
Height = 21 Height = 21
@ -101,6 +105,28 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm
Caption = '&Send' Caption = '&Send'
TabOrder = 1 TabOrder = 1
OnClick = btnSendClick OnClick = btnSendClick
ExplicitLeft = 269
end
object cmbControlCodePredefined: TComboBox
Left = 72
Top = 51
Width = 256
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
TabOrder = 2
ExplicitWidth = 220
end
object btnSendPredefined: TButton
Left = 334
Top = 51
Width = 75
Height = 21
Anchors = [akTop, akRight]
Caption = '&Send'
TabOrder = 3
OnClick = btnSendPredefinedClick
ExplicitLeft = 269
end end
end end
end end

View File

@ -23,10 +23,14 @@ type
lblControlCode: TLabel; lblControlCode: TLabel;
edtControlCode: TEdit; edtControlCode: TEdit;
btnSend: TButton; btnSend: TButton;
cmbControlCodePredefined: TComboBox;
btnSendPredefined: TButton;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure edtControlCodeChange(Sender: TObject); procedure edtControlCodeChange(Sender: TObject);
procedure btnSendClick(Sender: TObject); procedure btnSendClick(Sender: TObject);
procedure btnSendPredefinedClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject); procedure btnCloseClick(Sender: TObject);
private private
FContext: IX2ServiceContext; FContext: IX2ServiceContext;
@ -36,6 +40,8 @@ type
protected protected
procedure DoShow; override; procedure DoShow; override;
procedure UpdatePredefinedControlCodes; virtual;
function GetControlCode: Byte; function GetControlCode: Byte;
procedure SetStatus(const AMessage: string; AColor: TColor); procedure SetStatus(const AMessage: string; AColor: TColor);
@ -101,6 +107,12 @@ type
{ TX2ServiceContextGUIForm } { TX2ServiceContextGUIForm }
procedure TX2ServiceContextGUIForm.FormCreate(Sender: TObject);
begin
btnClose.Left := (ClientWidth - btnClose.Width) div 2;
end;
procedure TX2ServiceContextGUIForm.DoShow; procedure TX2ServiceContextGUIForm.DoShow;
var var
serviceThread: TX2ServiceThread; serviceThread: TX2ServiceThread;
@ -109,6 +121,8 @@ begin
if not Assigned(FServiceThread) then if not Assigned(FServiceThread) then
begin begin
UpdatePredefinedControlCodes;
SetStatus('Starting...', StatusColorStarting); SetStatus('Starting...', StatusColorStarting);
serviceThread := TX2ServiceThread.Create(Context, Service); serviceThread := TX2ServiceThread.Create(Context, Service);
serviceThread.OnStarted := serviceThread.OnStarted :=
@ -158,6 +172,19 @@ begin
end; end;
procedure TX2ServiceContextGUIForm.btnSendPredefinedClick(Sender: TObject);
var
code: Byte;
begin
if cmbControlCodePredefined.ItemIndex > -1 then
begin
code := Byte(cmbControlCodePredefined.Items.Objects[cmbControlCodePredefined.ItemIndex]);
(ServiceThread as TX2ServiceThread).SendControlCode(code);
end;
end;
procedure TX2ServiceContextGUIForm.btnCloseClick(Sender: TObject); procedure TX2ServiceContextGUIForm.btnCloseClick(Sender: TObject);
begin begin
Close; Close;
@ -176,6 +203,32 @@ begin
end; end;
procedure TX2ServiceContextGUIForm.UpdatePredefinedControlCodes;
var
serviceCustomControl: IX2ServiceCustomControl;
begin
cmbControlCodePredefined.Items.Clear;
if Supports(Service, IX2ServiceCustomControl, serviceCustomControl) then
begin
serviceCustomControl.EnumCustomControlCodes(
procedure(ACode: Byte; const ADescription: string)
begin
cmbControlCodePredefined.Items.AddObject(Format('%s (%d)', [ADescription, ACode]), TObject(ACode));
end);
cmbControlCodePredefined.Enabled := True;
cmbControlCodePredefined.ItemIndex := 0;
btnSendPredefined.Enabled := cmbControlCodePredefined.Items.Count > 0;
end else
begin
cmbControlCodePredefined.Enabled := False;
btnSendPredefined.Enabled := False;
end;
end;
function TX2ServiceContextGUIForm.GetControlCode: Byte; function TX2ServiceContextGUIForm.GetControlCode: Byte;
begin begin
Result := Byte(Min(Max(StrToIntDef(edtControlCode.Text, 0), 128), 255)); Result := Byte(Min(Max(StrToIntDef(edtControlCode.Text, 0), 128), 255));

View File

@ -40,6 +40,17 @@ type
end; end;
TX2ServiceCustomControlProc = reference to procedure(ACode: Byte; const ADescription: string);
{ Implement this to enable discovery of supported custom control codes
for use in interactive contexts. }
IX2ServiceCustomControl = interface
['{D6363AC5-3DD5-4897-90A7-6F63D82B6A74}']
procedure EnumCustomControlCodes(Yield: TX2ServiceCustomControlProc);
end;
TX2CustomService = class(TInterfacedObject, IX2Service) TX2CustomService = class(TInterfacedObject, IX2Service)
private private
FContext: IX2ServiceContext; FContext: IX2ServiceContext;