1
0
mirror of synced 2024-12-22 01:03:07 +01: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/
*.local
*.identcache

View File

@ -60,6 +60,11 @@ contains
X2UtPersistXMLBinding in '..\..\X2UtPersistXMLBinding.pas',
XMLDataBindingUtils in '..\..\XMLDataBindingUtils.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.

View File

@ -206,6 +206,13 @@
<DCCReference Include="..\..\XMLDataBindingUtils.pas"/>
<DCCReference Include="..\..\X2UtDelphiCompatibility.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">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>

View File

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

View File

@ -23,10 +23,14 @@ type
lblControlCode: TLabel;
edtControlCode: TEdit;
btnSend: TButton;
cmbControlCodePredefined: TComboBox;
btnSendPredefined: TButton;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure edtControlCodeChange(Sender: TObject);
procedure btnSendClick(Sender: TObject);
procedure btnSendPredefinedClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
private
FContext: IX2ServiceContext;
@ -36,6 +40,8 @@ type
protected
procedure DoShow; override;
procedure UpdatePredefinedControlCodes; virtual;
function GetControlCode: Byte;
procedure SetStatus(const AMessage: string; AColor: TColor);
@ -101,6 +107,12 @@ type
{ TX2ServiceContextGUIForm }
procedure TX2ServiceContextGUIForm.FormCreate(Sender: TObject);
begin
btnClose.Left := (ClientWidth - btnClose.Width) div 2;
end;
procedure TX2ServiceContextGUIForm.DoShow;
var
serviceThread: TX2ServiceThread;
@ -109,6 +121,8 @@ begin
if not Assigned(FServiceThread) then
begin
UpdatePredefinedControlCodes;
SetStatus('Starting...', StatusColorStarting);
serviceThread := TX2ServiceThread.Create(Context, Service);
serviceThread.OnStarted :=
@ -158,6 +172,19 @@ begin
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);
begin
Close;
@ -176,6 +203,32 @@ begin
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;
begin
Result := Byte(Min(Max(StrToIntDef(edtControlCode.Text, 0), 128), 255));

View File

@ -40,6 +40,17 @@ type
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)
private
FContext: IX2ServiceContext;