function CodeOnlyAndUpperCaseAndBlankReplace(
const S:
string):
string;
var
Index: integer;
begin
Result:= S;
Index:= Pos('
//', Result);
if Index > 1
then
Result:= Copy(Result, 1,
Index-1)
else
if Index = 1
then Result:= '
';
Index:= 1;
while Index <= Length(Result)
do
begin
if Result[
Index] <= '
'
then
begin
Delete(Result,
Index, 1);
Dec(
Index);
end;
Inc(
Index);
end;
Result:= UpperCase(Result);
end;
function GetValue(
var S:
string;
const Searchstr:
string;
var Value: integer): boolean;
var
I,
Index: integer;
Substr:
string;
begin
Result:= false;
Value:= 0;
Index:= Pos(Searchstr, S);
if Index > 0
then
begin
Substr:= '
';
I:=
Index+Length(Searchstr);
while I <= Length(S)
do
begin
if S[I]
in ['
-', '
0'..'
9']
then
Substr:= Substr+S[I]
else
Break;
Inc(I);
end;
Result:= TryStrToInt(Substr, Value);
if Result
then
Delete(S,
Index, Length(Searchstr+Substr));
end;
end;
procedure TForm1.Button10Click(Sender: TObject);
var
S, T, Result, Searchstr:
string;
Value: integer;
Error: boolean;
begin
Result:= '
';
S:= '
DELTAX1DELTAY-63 // Test';
Error:= false;
S:= CodeOnlyAndUpperCaseAndBlankReplace(S);
T:= S;
Searchstr:='
DELTAX';
if (
not Error)
and GetValue(S, Searchstr, Value)
then
begin
Result:= Result+Searchstr+IntToStr(Value);
T:= S; Error:= GetValue(T, Searchstr, Value);
end;
Searchstr:='
DELTAY';
if (
not Error)
and GetValue(S, Searchstr, Value)
then
begin
Result:= Result+Searchstr+IntToStr(Value);
T:= S; Error:= GetValue(T, Searchstr, Value);
end;
Searchstr:='
X';
if (
not Error)
and GetValue(S, Searchstr, Value)
then
begin
Result:= Result+Searchstr+IntToStr(Value);
T:= S; Error:= GetValue(T, Searchstr, Value);
end;
Searchstr:='
Y';
if (
not Error)
and GetValue(S, Searchstr, Value)
then
begin
Result:= Result+Searchstr+IntToStr(Value);
T:= S; Error:= GetValue(T, Searchstr, Value);
end;
Searchstr:='
HF';
if (
not Error)
and GetValue(S, Searchstr, Value)
then
begin
Result:= Result+Searchstr+IntToStr(Value);
T:= S; Error:= GetValue(T, Searchstr, Value);
end;
if Length(S) <> 0
then Error:= true;
if Error
then
Showmessage('
Error: '+S)
else
Showmessage('
Code: '+Result);
end;
end.