Skip to content

Commit d23249e

Browse files
committed
Accept sexadecimal input
1 parent df74f31 commit d23249e

File tree

2 files changed

+71
-15
lines changed

2 files changed

+71
-15
lines changed

component/indiclient/pu_indigui.lfm

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
object f_indigui: Tf_indigui
22
Left = 572
3-
Height = 520
3+
Height = 525
44
Top = 53
5-
Width = 670
5+
Width = 677
66
Caption = 'INDI'
7-
ClientHeight = 520
8-
ClientWidth = 670
9-
DesignTimePPI = 95
7+
ClientHeight = 525
8+
ClientWidth = 677
109
OnClose = FormClose
1110
OnCreate = FormCreate
1211
OnDestroy = FormDestroy
1312
OnShow = FormShow
1413
object dev: TPageControl
1514
Left = 0
16-
Height = 425
15+
Height = 429
1716
Top = 0
18-
Width = 670
17+
Width = 677
1918
Align = alClient
19+
ParentFont = False
2020
TabOrder = 0
2121
end
2222
object Splitter1: TSplitter
2323
Cursor = crVSplit
2424
Left = 0
2525
Height = 5
26-
Top = 425
27-
Width = 670
26+
Top = 429
27+
Width = 677
2828
Align = alBottom
2929
Beveled = True
3030
ParentColor = False
3131
ResizeAnchor = akBottom
3232
end
3333
object msg: TMemo
3434
Left = 0
35-
Height = 90
36-
Top = 430
37-
Width = 670
35+
Height = 91
36+
Top = 434
37+
Width = 677
3838
Align = alBottom
39+
ParentFont = False
3940
ReadOnly = True
4041
ScrollBars = ssAutoVertical
4142
TabOrder = 1

component/indiclient/pu_indigui.pas

+58-3
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,43 @@ function SXToStr(de: double): string;
585585
Result := d + ':' + m + ':' + s;
586586
end;
587587

588+
function StrToSX(sx: string): double;
589+
const sep = ':';
590+
var
591+
s, p: integer;
592+
t: string;
593+
begin
594+
try
595+
sx := StringReplace(sx, ' ', '0', [rfReplaceAll]);
596+
if copy(sx, 1, 1) = '-' then
597+
s := -1
598+
else
599+
s := 1;
600+
p := pos(sep, sx);
601+
if p = 0 then
602+
Result := StrToFloatDef(sx, -9999)
603+
else
604+
begin
605+
t := copy(sx, 1, p - 1);
606+
Delete(sx, 1, p);
607+
Result := StrToIntDef(t, 0);
608+
p := pos(sep, sx);
609+
if p = 0 then
610+
Result := Result + s * StrToIntDef(sx, 0) / 60
611+
else
612+
begin
613+
t := copy(sx, 1, p - 1);
614+
Delete(sx, 1, p);
615+
Result := Result + s * StrToIntDef(t, 0) / 60;
616+
Result := Result + s * StrToFloatDef(sx, 0) / 3600;
617+
end;
618+
end;
619+
except
620+
Result := -9999;
621+
end;
622+
623+
end;
624+
588625
function IndiFormatFloat(x: double; fmt: string): string;
589626
begin
590627
if copy(fmt, Length(fmt), 1) = 'm' then
@@ -602,6 +639,20 @@ function IndiFormatFloat(x: double; fmt: string): string;
602639
end;
603640
end;
604641

642+
function IndiStr2Float(txt, fmt: string; out value: double): integer;
643+
begin
644+
if copy(fmt, Length(fmt), 1) = 'm' then begin
645+
value:=StrToSX(txt);
646+
if value=-9999 then
647+
result:=1
648+
else
649+
result:=0;
650+
end
651+
else begin
652+
val(txt, value, result);
653+
end;
654+
end;
655+
605656
procedure Tf_indigui.CreateNumberWidget(iprop: TIndiProp);
606657
var
607658
lbl: TLabel;
@@ -1036,11 +1087,15 @@ procedure Tf_indigui.SetButtonClick(Sender: TObject);
10361087
entry := TEdit(iprop.entry.Objects[j]);
10371088
if entry.Text <> '' then
10381089
begin
1039-
val(entry.Text, Value, er);
1040-
if er = 0 then
1090+
er:=IndiStr2Float(entry.Text,nvp.np[i].format,Value);
1091+
if er = 0 then begin
10411092
nvp.np[i].Value := Value;
1093+
buf := buf + nvp.np[i].Name + '=' + FloatToStr(nvp.np[i].Value) + ' ';
1094+
end
1095+
else begin
1096+
buf := buf + nvp.np[i].Name + ' not numeric ' +entry.Text+ ' ';
1097+
end;
10421098
entry.Clear;
1043-
buf := buf + nvp.np[i].Name + '=' + FloatToStr(nvp.np[i].Value) + ' ';
10441099
end;
10451100
end;
10461101
indiclient.sendNewNumber(nvp);

0 commit comments

Comments
 (0)