unit uanycommand;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;
  
type
  TTipRetDate = (rdDay, rdMonth, rdYear, rdQuarta, rdWeek);

  TAnyCommandDate = class
    function RetDate(InDate: TDateTime; InTip: TTipRetDate): Word;
//    function GetCountDayOfYearMonth(const Year: Word; const Month: Byte = [1..12]): Byte;
    function Year4ToYear2(InYear: Word): Byte;
    function bDbMwYToTDateTime(const Day, Month: Byte; const Year: Word): TDateTime;
    procedure DateFBPFactsToYearMonthDay(const DateFBPFacts: string; var Year: integer; var Month, Day: Byte);
  end;

  TAnyCommandString = class
    function CutStr(var InStr: string; var Count: integer): string;
    procedure DeleteAllCode(var Str: string; C: Char);
    procedure AddPathDelim(var SStr: string);
    function GetPathFromFullNameFile(var NF: string): string;
  {  procedure ShowUTF8BasicLatin;
    procedure ShowUTF8Latin1Supplement;
    procedure ShowUTF8LatinExtendedA;
    procedure ShowUTF8LatinExtendedB;
    procedure ShowUTF8IPAExtensions;
    procedure ShowUTF8SpacingModifierLetters;
    procedure ShowUTF8CombiningDiacriticalMarks;
    procedure ShowUTF8Cyrilic;
    procedure ShowUTF8LatinExtendedAdditional;
    procedure ShowUTF8GeneralPunctuation;
    procedure ShowUTF8SubscriptsAndSuperscripts;
    procedure ShowUTF8CurrencySybols;
    procedure ShowUTF8CombiningDiacritikalMarksForSymbols;
    procedure ShowUTF8LitterLikeSymbols;
    procedure ShowUTF8NumberForms;
    procedure ShowUTF8Arrows;
    procedure ShowUTF8MathematicalOperators;
    procedure ShowUTF8MiscellaneousTechnical;
    procedure ShowUTF8ControlPictures;
    procedure ShowUTF8OpticalCharacterRecognition;
    procedure ShowUTF8EnclosedAlphanumerics;
    procedure ShowUTF8BoxDrawing;
    procedure ShowUTF8BlockElements;
    procedure ShowUTF8GeometricShapes;
    procedure ShowUTF8MiscellaneousSymbols;
    procedure ShowUTF8Dingbats;    }
    procedure Windows1251ToUTF8(var Str: string);
    procedure UTF8ToWindows1251(var Str: string);
    procedure OEM866ToUTF8(var Str: string);
    procedure UTF8ToOEM866(var Str: string);
    procedure OEM866ToWindows1251(var Str: string);
    procedure Windows1251ToOEM866(var Str: string);
  end;

var
  AnyCommandDate: TAnyCommandDate;
  AnyCommandString: TAnyCommandString;

implementation

//uses fhidememo;

function TAnyCommandDate.RetDate(InDate: TDateTime; InTip: TTipRetDate): Word;
var
  xYear, xMonth, xDay, xWeek: Word;
begin
  Result := 0;
  if not DecodeDateFully(InDate, xYear, xMonth, xDay, xWeek) then Exit;
  case InTip of
    rdDay: Result := xDay;
    rdMonth: Result := xMonth;
    rdYear: Result := xYear;
    rdWeek: Result := xWeek;
    rdQuarta: if xMonth < 4 then Result := 1
              else if xMonth < 7 then Result := 2
              else if xMonth < 10 then Result := 3
              else Result := 4;
  end;
end;

{function TAnyCommandDate.GetCountDayOfYearMonth(const Year: Word; const Month: Byte = [1..12]): Byte;
var
  Dec: integer;
  Vis: Boolean;
begin
  Result := 1;
  Vis := false;
  Dec := Year mod 4;
  if Dec = 0 then
    begin
      Vis := true;
      Dec := Year mod 100;
      if Dec = 0 then
        begin
          Vis := false;
          Dec := Year mod 400;
          if Dec = 0 then
            Vis := true;
        end;
    end;
  case Month of
    1, 3, 5, 7, 8, 10, 12: Result := 31;
    4, 6, 9, 11: Result := 30;
    2: if Vis then Result := 29 else Result := 28;
  end;
end;
 }
function TAnyCommandDate.Year4ToYear2(InYear: Word): Byte;
var
  xS: string;
  xL: integer;
begin
  Result := 0;
  xS := IntToStr(InYear);
  xL := length(xS);
  if xL > 4 then Delete(xS, 5, xL - 4);
  Delete(xS, 1, 2);
  Result := StrToIntDef(xS, 0);
end;

function TAnyCommandDate.bDbMwYToTDateTime(const Day, Month: Byte; const Year: Word): TDateTime;
var
  sW, y: string;
begin
  Result := Now;
  sW := IntToStr(Day) + '-' + IntToStr(Month) + '-';
  y := IntToStr(Year);
  if length(y) > 4 then Exit;
  sW := sW + copy (y, 3, 2);
  Result := StrToDateTimeDef(sW, Now);
end;

procedure TAnyCommandDate.DateFBPFactsToYearMonthDay(const DateFBPFacts: string; var Year: Integer; var Month, Day: Byte);
var
  sW, sYear, sMonth, sDay: string;
  iPos: integer;
begin
  Year:= -1;
  Month:= 0;
  sW := DateFBPFacts;
  if Length(sW) < 8 then Exit;
  iPos:= Pos('.', sW);
  if (iPos = 0) or (iPos > 3) then Exit;
  sDay := copy(sW, 1, pred(iPos));
  Delete(sW, 1, iPos);
  if Length(sW) < 6 then Exit;
  iPos:= Pos('.', sW);
  if (iPos = 0) or (iPos > 3) then Exit;
  sMonth:= copy(sW, 1, pred(iPos));
  Delete(sW, 1, iPos);
  if Length(sW) <> 4 then Exit;
  sYear:= sW;
  Year:= StrToIntDef(sYear, -1);
  Month:= StrToIntDef(sMonth, 0);
  Day := StrToIntDef(sDay, 0);
  if Month > 12 then Month := 0;
 // if Day > GetCountDayOfYearMonth(Year, Month) then Day := 0;
end;

function TAnyCommandString.CutStr(var InStr: string; var Count: integer): string;
var
  xL: integer;
begin
  xL := length(InStr);
  if Count > xL then Count := xL;
  Result := copy(InStr, 1, Count);
  Delete(InStr, 1, Count);
end;

procedure TAnyCommandString.DeleteAllCode(var Str: string; C: Char);
var
  GStr, Nstr: string;
  xL, iFor: integer;
begin
  GStr := Str;
  NStr := '';
  xL := length(GStr);
  for iFor := 1 to xL do
    if not (GStr[iFor] = C) then
      NStr := NStr + GStr[iFor];
  Str := NStr;
end;

procedure TAnyCommandString.AddPathDelim(var SStr: string);
var
  xL: integer;
begin
  xL := length(SStr);
  if xL < 1 then
    begin
      SStr := PathDelim;
      Exit;
    end;
  if SStr[xL] <> PathDelim then SStr := SStr + PathDelim;
end;

function TAnyCommandString.GetPathFromFullNameFile(var NF: string): string;
var
  GStr: string;
  iFor, xL, p: integer;
begin
  Result := '';
  GStr := NF;
  xL := Length(GStr);
  if xL < 2 then Exit;
  p := 0;
  for iFor:= xL downto 1 do
    if GStr[iFor] = PathDelim then
      begin
        p := iFor;
        break;
      end;
  if p = 0 then Exit;
  Result := LeftStr(GStr, p);
  Delete(GStr, 1, p);
  NF := GStr;
end;

{procedure TAnyCommandString.ShowUTF8BasicLatin;
var
  iFor: integer;
begin
//  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $00 to $7F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr(iFor, 2) +  ' : ' + chr(iFor));
end;
}
{procedure TAnyCommandString.ShowUTF8Latin1Supplement;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C2, 2) + hexStr(iFor, 2) + ' : ' + #$C2 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C3, 2) + hexStr(iFor, 2) + ' : ' + #$C3 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8LatinExtendedA;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C4, 2) + hexStr(iFor, 2) + ' : ' + #$C4 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C5, 2) + hexStr(iFor, 2) + ' : ' + #$C5 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8LatinExtendedB;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C6, 2) + hexStr(iFor, 2) + ' : ' + #$C6 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C7, 2) + hexStr(iFor, 2) + ' : ' + #$C7 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C8, 2) + hexStr(iFor, 2) + ' : ' + #$C8 + chr(iFor));
  for iFor := $80 to $8F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C9, 2) + hexStr(iFor, 2) + ' : ' + #$C9 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8IPAExtensions;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $90 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($C9, 2) + hexStr(iFor, 2) + ' : ' + #$C9 + chr(iFor));
  for iFor := $80 to $AF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($CA, 2) + hexStr(iFor, 2) + ' : ' + #$CA + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8SpacingModifierLetters;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $B0 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($CA, 2) + hexStr(iFor, 2) + ' : ' + #$CA + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($CB, 2) + hexStr(iFor, 2) + ' : ' + #$CB + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8CombiningDiacriticalMarks;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($CC, 2) + hexStr(iFor, 2) + ' : ' + #$CC + chr(iFor));
  for iFor := $80 to $AF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($CD, 2) + hexStr(iFor, 2) + ' : ' + #$CD + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8Cyrilic;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($D0, 2) + hexStr(iFor, 2) + ' : ' + #$D0 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($D1, 2) + hexStr(iFor, 2) + ' : ' + #$D1 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($D2, 2) + hexStr(iFor, 2) + ' : ' + #$D2 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($D3, 2) + hexStr(iFor, 2) + ' : ' + #$D3 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8LatinExtendedAdditional;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E1B8, 4) + hexStr(iFor, 2) + ' : ' + #$E1#$B8 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E1B9, 4) + hexStr(iFor, 2) + ' : ' + #$E1#$B9 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E1BA, 4) + hexStr(iFor, 2) + ' : ' + #$E1#$BA + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E1BB, 4) + hexStr(iFor, 2) + ' : ' + #$E1#$BB + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8GeneralPunctuation;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E280, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$80 + chr(iFor));
  for iFor := $80 to $AF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E281, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$81 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8SubscriptsAndSuperscripts;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $B0 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E281, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$81 + chr(iFor));
  for iFor := $80 to $9F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E282, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$82 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8CurrencySybols;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $A0 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E282, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$82 + chr(iFor));
  for iFor := $80 to $8F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E283, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$83 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8CombiningDiacritikalMarksForSymbols;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $90 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E283, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$83 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8LitterLikeSymbols;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E284, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$84 + chr(iFor));
  for iFor := $80 to $8F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E285, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$85 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8NumberForms;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $90 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E285, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$85 + chr(iFor));
  for iFor := $80 to $8F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E286, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$86 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8Arrows;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $90 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E286, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$86 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E287, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$87 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8MathematicalOperators;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E288, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$88 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E289, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$89 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E28A, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$8A + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E28B, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$8B + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8MiscellaneousTechnical;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E28C, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$8C + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E28D, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$8D + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E28E, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$8E + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E28F, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$8F + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8ControlPictures;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E290, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$90 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8OpticalCharacterRecognition;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $9F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E291, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$91 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8EnclosedAlphanumerics;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $A0 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E291, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$91 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E292, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$92 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E293, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$93 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8BoxDrawing;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E294, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$94 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E295, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$95 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8BlockElements;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $9F do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E296, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$96 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8GeometricShapes;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $A0 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E296, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$96 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E297, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$97 + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8MiscellaneousSymbols;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E298, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$98 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E299, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$99 + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E29A, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$9A + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E29B, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$9B + chr(iFor));
end;

procedure TAnyCommandString.ShowUTF8Dingbats;
var
  iFor: integer;
begin
  FormHideMemo.ListBoxHideMemo.Items.Clear;
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E29C, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$9C + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E29D, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$9D + chr(iFor));
  for iFor := $80 to $BF do
    FormHideMemo.ListBoxHideMemo.Items.Add(hexStr($E29E, 4) + hexStr(iFor, 2) + ' : ' + #$E2#$9E + chr(iFor));
end;
}
procedure TAnyCommandString.Windows1251ToUTF8(var Str: string);
const
  bRD0: Byte = ($C0 - $90);
  bRD1: Byte = ($F0 - $80);
var
  xCh, GStr, NStr: string;
  xL, iFor: integer;
  xChr: Char;
begin
  GStr := Str;
  NStr := '';
  xL := length(Str);
  for iFor := 1 to xL do
    begin
      xCh := #$20;
      xChr := GStr[iFor];
    if (xChr >= #$00) and (xChr <= #$7F) then {Первая половина без изменений}
      xCh := xChr
    else
      if (xChr >= #$C0) and (xChr <= #$EF) then {А-п}
        xCh := #$D0 + chr(ord(xChr) - bRD0)
      else
        if (xChr >= #$F0) and (xChr <= #$FF) then {р-я}
          xCh := #$D1 + chr(ord(xChr) - bRD1)
        else
          case ord(xChr) of
            $80: xCh := #$D0#$82;
            $81: xCh := #$D0#$83;
            $82: xCh := #$E2#$80#$9A;
            $83: xCh := #$D1#$93;
            $84: xCh := #$E2#$80#$0E;
            $93: xCh := #$E2#$80#$9C;
            $94: xCh := #$E2#$80#$9D;
            $AB: xCh := #$C2#$AB;
            $BB: xCh := #$C2#$BB;
            $85: xCh := #$E2#$80#$A6;
            $86: xCh := #$E2#$80#$A0;
            $87: xCh := #$E2#$80#$A1;
            $88: xCh := #$E2#$82#$AC;
            $89: xCh := #$E2#$80#$B0;
            $8A: xCh := #$D0#$89;
            $8B: xCh := #$E2#$80#$B9;
            $9B: xCh := #$E2#$80#$BA;
            $8C: xCh := #$D0#$8A;
            $8D: xCh := #$D0#$8C;
            $8E: xCh := #$D0#$8B;
            $8F: xCh := #$D0#$8F;
            $90: xCh := #$D1#$92;
            $91: xCh := #$E2#$80#$98;
            $92: xCh := #$E2#$80#$99;
            $95: xCh := #$E2#$80#$A2;
            $96: xCh := #$E2#$80#$93;
            $97: xCh := #$E2#$80#$92;
            $AD: xCh := #$E2#$80#$94;
            $99: xCh := #$E2#$84#$A2;
            $9A: xCh := #$D1#$99;
            $9C: xCh := #$D1#$9A;
            $9D: xCh := #$D1#$9C;
            $9E: xCh := #$D1#$9B;
            $9F: xCh := #$D1#$9F;
            $A1: xCh := #$D0#$8E;
            $A2: xCh := #$D1#$9E;
            $A3: xCh := #$D0#$88;
            $A4: xCh := #$C2#$A4;
            $A5: xCh := #$D2#$90;
            $A6: xCh := #$C2#$A6;
            $A7: xCh := #$C2#$A7;
            $A8: xCh := #$D0#$81;
            $A9: xCh := #$C2#$A9;
            $AA: xCh := #$D0#$84;
            $AC: xCh := #$C2#$AC;
            $AF: xCh := #$D0#$87;
            $B0: xCh := #$C2#$B0;
            $B1: xCh := #$C2#$B1;
            $B2: xCh := #$D0#$86;
            $B3: xCh := #$D1#$96;
            $B4: xCh := #$D2#$91;
            $B5: xCh := #$C2#$B5;
            $B6: xCh := #$C2#$B6;
            $B7: xCh := #$C2#$B7;
            $B8: xCh := #$D1#$91;
            $B9: xCh := #$E2#$84#$96;
            $BA: xCh := #$D1#$94;
            $BC: xCh := #$D1#$98;
            $BD: xCh := #$D0#$85;
            $BE: xCh := #$D1#$95;
            $BF: xCh := #$D1#$97;
          end;
      NStr := NStr + xCh;
    end;
  Str := NStr;
end;

procedure TAnyCommandString.UTF8ToWindows1251(var Str: string);
const
  bRD0: Byte = ($C0 - $90);
  bRD1: Byte = ($F0 - $80);
var
  GStr, NStr: string;
  xChr, xP: Char;
  xL, iFor: integer;
  xGr1, xGr2: Char;
  bitn: Boolean = true {true - 2 байта, false - 3 байта};
begin
  xL := length(Str);
  GStr := Str;
  NStr := '';
  for iFor := 1 to xL do
    begin
      xChr := #$20;
      xP := GStr[iFor];
      if (xP >= #$00) and (xP <= #$7F) then {Первая половина без изменений}
        begin
          xChr := xP;
          xGr1:= #$00;
          xGr2:= #$00;
        end
      else
        if (xP = #$C2) or (xP = #$D0) or (xP = #$D1) then
          begin
            xGr1 := xP;
            xGr2 := #$00;
            bitn := true;
          end
        else
          if xP = #$E2 then
            begin
              xGr1 := xP;
              xGr2 := #$00;
              bitn := false;
            end
          else
            if (xP >= #$80) and (xP <= #$BF) then
              if (not bitn) and (xGr2 = #$00) then
                begin
                  xGr2 := xP;
                  bitn := true;
                end
              else
                begin
                  if xGr2 = #$00 then
                    if xGr1 = #$D0 then
                      if (xP >= #$90) and (xP <= #$BF) then
                        xChr := chr(ord(xP) + brD0)
                      else
                        case ord(xP) of
                          $81: xChr := #$A8;
                          $82: xChr := #$80;
                          $83: xChr := #$81;
                          $84: xChr := #$AA;
                          $85: xChr := #$BD;
                          $86: xChr := #$B2;
                          $87: xChr := #$AF;
                          $88: xChr := #$A3;
                          $89: xChr := #$8A;
                          $8A: xChr := #$8C;
                          $8B: xChr := #$8E;
                          $8C: xChr := #$8D;
                          $8E: xChr := #$A1;
                          $8F: xChr := #$8F;
                        end
                    else
                      if xGr1 = #$D1 then
                        if (xP >= #$80) and (xP <= #$8F) then
                          xChr := chr(ord(xP) + bRD1)
                        else
                          case ord(xP) of
                            $91: xChr := #$B8;
                            $92: xChr := #$90;
                            $93: xChr := #$83;
                            $94: xChr := #$BA;
                            $95: xChr := #$BE;
                            $96: xChr := #$B3;
                            $97: xChr := #$BF;
                            $98: xChr := #$BC;
                            $99: xChr := #$9A;
                            $9A: xChr := #$9C;
                            $9B: xChr := #$9E;
                            $9C: xChr := #$9D;
                            $9E: xChr := #$A2;
                            $9F: xChr := #$9F;
                          end
                      else
                        if xGr1 = #$C2 then
                          case ord(xP) of
                            $A4: xChr := xP;
                            $A6: xChr := xP;
                            $A7: xChr := xP;
                            $A9: xChr := xP;
                            $AB: xChr := xP;
                            $AC: xChr := xP;
                            $B0: xChr := xP;
                            $B1: xChr := xP;
                            $B5: xChr := xP;
                            $B6: xChr := xP;
                            $B7: xChr := xP;
                            $BB: xChr := xP;
                          end
                  else
                    case ord(xGr2) of
                      $82: if xP = #$AC then xChr := #$88;
                      $84: case ord(xP) of
                             $A2: xChr := #$99;
                             $96: xChr := #$B9;
                           end;
                      $80: case ord(xP) of
                             $92: xChr := #$97;
                             $93: xChr := #$96;
                             $94: xChr := #$AD;
                             $98: xChr := #$91;
                             $99: xChr := #$92;
                             $9A: xChr := #$82;
                             $9C: xChr := #$93;
                             $9D: xChr := #$94;
                             $A0: xChr := #$86;
                             $A1: xChr := #$87;
                             $A2: xChr := #$95;
                             $A6: xChr := #$85;
                             $B0: xChr := #$89;
                             $B9: xChr := #$8B;
                             $BA: xChr := #$9B;
                             $0E: xChr := #$84;
                           end;
                    end;
                  xGr1 := #$00;
                end;
      if xGr1 = #$00 then
        NStr := NStr + xChr;
    end;
  Str := NStr;
end;

procedure TAnyCommandString.OEM866ToUTF8(var Str: string);
const
  bRD0: Byte = ($90 - $80);
  bRD1: Byte = ($E0 - $80);
var
  xCh, GStr, NStr: string;
  xL, iFor: integer;
  xChr: Char;
begin
  GStr := Str;
  NStr := '';
  xL := length(Str);
  for iFor := 1 to xL do
    begin
      xCh := #$20;
      xChr := GStr[iFor];
    if (xChr >= #$00) and (xChr <= #$7F) then {Первая половина без изменений}
      xCh := xChr
    else
      if (xChr >= #$80) and (xChr <= #$AF) then {А-п}
        xCh := #$D0 + chr(ord(xChr) + bRD0)
      else
        if (xChr >= #$E0) and (xChr <= #$EF) then {р-я}
          xCh := #$D1 + chr(ord(xChr) - bRD1)
        else
          case ord(xChr) of
            $B0: xCh := #$E2#$96#$91;
            $B1: xCh := #$E2#$96#$92;
            $B2: xCh := #$E2#$96#$93;
            $B3: xCh := #$E2#$94#$82;
            $B4: xCh := #$E2#$94#$A4;
            $B5: xCh := #$E2#$95#$A1;
            $B6: xCh := #$E2#$95#$A2;
            $B7: xCh := #$E2#$95#$96;
            $B8: xCh := #$E2#$95#$95;
            $B9: xCh := #$E2#$95#$A3;
            $BA: xCh := #$E2#$95#$91;
            $BB: xCh := #$E2#$95#$97;
            $BC: xCh := #$E2#$95#$9D;
            $BD: xCh := #$E2#$95#$9C;
            $BE: xCh := #$E2#$95#$9B;
            $BF: xCh := #$E2#$95#$AE;
            $C0: xCh := #$E2#$95#$B0;
            $C1: xCh := #$E2#$94#$B4;
            $C2: xCh := #$E2#$94#$AC;
            $C3: xCh := #$E2#$94#$9C;
            $C4: xCh := #$E2#$94#$80;
            $C5: xCh := #$E2#$94#$BC;
            $C6: xCh := #$E2#$95#$9E;
            $C7: xCh := #$E2#$95#$9F;
            $C8: xCh := #$E2#$95#$9A;
            $C9: xCh := #$E2#$95#$94;
            $CA: xCh := #$E2#$95#$A9;
            $CB: xCh := #$E2#$95#$A6;
            $CC: xCh := #$E2#$95#$A0;
            $CD: xCh := #$E2#$95#$90;
            $CE: xCh := #$E2#$95#$AC;
            $CF: xCh := #$E2#$95#$A7;
            $D0: xCh := #$E2#$95#$A8;
            $D1: xCh := #$E2#$95#$A4;
            $D2: xCh := #$E2#$95#$A5;
            $D3: xCh := #$E2#$95#$99;
            $D4: xCh := #$E2#$95#$98;
            $D5: xCh := #$E2#$95#$92;
            $D6: xCh := #$E2#$95#$93;
            $D7: xCh := #$E2#$95#$AB;
            $D8: xCh := #$E2#$95#$AA;
            $D9: xCh := #$E2#$95#$AF;
            $DA: xCh := #$E2#$95#$AD;
            $DB: xCh := #$E2#$96#$88;
            $DC: xCh := #$E2#$96#$84;
            $DD: xCh := #$E2#$96#$8C;
            $DE: xCh := #$E2#$96#$90;
            $DF: xCh := #$E2#$95#$80;
            $F0: xCh := #$D0#$81;
            $F1: xCh := #$D1#$91;
            $F2: xCh := #$D0#$84;
            $F3: xCh := #$D1#$94;
            $F4: xCh := #$D0#$87;
            $F5: xCh := #$D1#$97;
            $F6: xCh := #$D0#$8E;
            $F7: xCh := #$D1#$9E;
            $F8: xCh := #$C2#$B0;
            $F9: xCh := #$E2#$80#$A2;
            $FA: xCh := #$C2#$B7;
            $FB: xCh := #$E2#$8E#$B7;
            $FC: xCh := #$E2#$84#$96;
            $FD: xCh := #$C2#$A4;
            //$FE: xCh := #$C2#$A4; //
            //$FF: xCh := #$C2#$A4; //
          end;
      NStr := NStr + xCh;
    end;
  Str := NStr;
end;

procedure TAnyCommandString.UTF8ToOEM866(var Str: string);
const
  bRD0: Byte = ($90 - $80);
  bRD1: Byte = ($E0 - $80);
var
  GStr, NStr: string;
  xChr, xP: Char;
  xL, iFor: integer;
  xGr1, xGr2: Char;
  bitn: Boolean = true {true - 2 байта, false - 3 байта};
begin
  xL := length(Str);
  GStr := Str;
  NStr := '';
  for iFor := 1 to xL do
    begin
      xChr := #$20;
      xP := GStr[iFor];
      if (xP >= #$00) and (xP <= #$7F) then {Первая половина без изменений}
        begin
          xChr := xP;
          xGr1:= #$00;
          xGr2:= #$00;
        end
      else
        if (xP = #$C2) or (xP = #$D0) or (xP = #$D1) then
          begin
            xGr1 := xP;
            xGr2 := #$00;
            bitn := true;
          end
        else
          if xP = #$E2 then
            begin
              xGr1 := xP;
              xGr2 := #$00;
              bitn := false;
            end
          else
            if (xP >= #$80) and (xP <= #$BF) then
              if (not bitn) and (xGr2 = #$00) then
                begin
                  xGr2 := xP;
                  bitn := true;
                end
              else
                begin
                  if xGr2 = #$00 then
                    if xGr1 = #$D0 then
                      if (xP >= #$90) and (xP <= #$BF) then
                        xChr := chr(ord(xP) - brD0)
                      else
                        case ord(xP) of
                          $81: xChr := #$F0;
                          $84: xChr := #$F2;
                          $87: xChr := #$F4;
                          $8E: xChr := #$F6;
                        end
                    else
                      if xGr1 = #$D1 then
                        if (xP >= #$80) and (xP <= #$8F) then
                          xChr := chr(ord(xP) + bRD1)
                        else
                          case ord(xP) of
                            $91: xChr := #$F1;
                            $94: xChr := #$F3;
                            $97: xChr := #$F5;
                            $9E: xChr := #$F7;
                          end
                      else
                        if xGr1 = #$C2 then
                          case ord(xP) of
                            $A4: xChr := #$FD;
                            $B0: xChr := #$F8;
                            $B7: xChr := #$FA;
                          end
                  else
                    case ord(xGr2) of
                      $8E: if xP = #$B7 then xChr := #$FB;
                      $84: if xP = #$96 then xChr := #$FC;
                      $80: if xP = #$A2 then xChr := #$F9;
                      $94: case ord(xP) of
                             $80: xChr := #$C4;
                             $82: xChr := #$B3;
                             $9C: xChr := #$C3;
                             $A4: xChr := #$B4;
                             $AC: xChr := #$C2;
                             $B4: xChr := #$C1;
                             $BC: xChr := #$C5;
                           end;
                      $95: case ord(xP) of
                             $A1: xChr := #$B5;
                             $A2: xChr := #$B6;
                             $96: xChr := #$B7;
                             $95: xChr := #$B8;
                             $A3: xChr := #$B9;
                             $91: xChr := #$BA;
                             $97: xChr := #$BB;
                             $9D: xChr := #$BC;
                             $9C: xChr := #$BD;
                             $9B: xChr := #$BE;
                             $AE: xChr := #$BF;
                             $B0: xChr := #$C0;
                             $9E: xChr := #$C6;
                             $9F: xChr := #$C7;
                             $9A: xChr := #$C8;
                             $94: xChr := #$C9;
                             $A9: xChr := #$CA;
                             $A6: xChr := #$CB;
                             $A0: xChr := #$CC;
                             $90: xChr := #$CD;
                             $AC: xChr := #$CE;
                             $A7: xChr := #$CF;
                             $A8: xChr := #$D0;
                             $A4: xChr := #$D1;
                             $A5: xChr := #$D2;
                             $99: xChr := #$D3;
                             $98: xChr := #$D4;
                             $92: xChr := #$D5;
                             $93: xChr := #$D6;
                             $AB: xChr := #$D7;
                             $AA: xChr := #$D8;
                             $AF: xChr := #$D9;
                             $AD: xChr := #$DA;
                             $80: xChr := #$DF;
                           end;
                      $96: case ord(xP) of
                             $90: xChr := #$DE;
                             $91: xChr := #$B0;
                             $92: xChr := #$B1;
                             $93: xChr := #$B2;
                             $88: xChr := #$DB;
                             $84: xChr := #$DC;
                             $8C: xChr := #$DD;
                           end;
                    end;
                  xGr1 := #$00;
                end;
      if xGr1 = #$00 then
        NStr := NStr + xChr;
    end;
  Str := NStr;
end;

procedure TAnyCommandString.OEM866ToWindows1251(var Str: string);
const
  Ap: Byte = ($C0 - $80);
  rya: Byte = ($F0 - $E0);
var
  iFor, xL: integer;
  GStr, NStr: string;
  xCh, xChr: Char;
begin
  NStr := '';
  GStr := Str;
  xL := length(GStr);
  for iFor := 1 to xL do
    begin
      xChr := #$20;
      xCh := GStr[iFor];
      if (xCh >= #$00) and (xCh <= #$7F) then {Первая часть без изменений}
        xChr := xCh
      else
        if (xCh >= #$80) and (xCh <= #$AF) then
          xChr := chr(ord(xCh) + Ap)
        else
          if (xCh >= #$E0) and (xCh <= #$EF) then
            xChr := chr(ord(xCh) + rya)
          else
            case ord(xCh) of
              {Псевдографика}
              $B0: xChr := #$A9;
              $B1: xChr := #$AE;
              $B2: xChr := #$B5;
              $B3: xChr := #$A6;
              $B4: xChr := #$A6;
              $B5: xChr := #$A6;
              $B6: xChr := #$A6;
              $B9: xChr := #$A6;
              $BA: xChr := #$A6;
              $C3: xChr := #$A6;
              $C6: xChr := #$A6;
              $C7: xChr := #$A6;
              $CC: xChr := #$A6;
              $B7: xChr := #$2B;
              $B8: xChr := #$2B;
              $BB: xChr := #$2B;
              $BC: xChr := #$2B;
              $BD: xChr := #$2B;
              $BE: xChr := #$2B;
              $BF: xChr := #$2B;
              $C0: xChr := #$2B;
              $C5: xChr := #$2B;
              $C8: xChr := #$2B;
              $C9: xChr := #$2B;
              $CE: xChr := #$2B;
              $D3: xChr := #$2B;
              $D4: xChr := #$2B;
              $D5: xChr := #$2B;
              $D6: xChr := #$2B;
              $D7: xChr := #$2B;
              $D8: xChr := #$2B;
              $D9: xChr := #$2B;
              $DA: xChr := #$2B;
              $C1: xChr := #$97;
              $C2: xChr := #$97;
              $C4: xChr := #$97;
              $CA: xChr := #$97;
              $CB: xChr := #$97;
              $CD: xChr := #$97;
              $CF: xChr := #$97;
              $D0: xChr := #$97;
              $D1: xChr := #$97;
              $D2: xChr := #$97;
              {...}
              $F0: xChr := #$A8;
              $F1: xChr := #$B8;
              $F2: xChr := #$AA;
              $F3: xChr := #$BA;
              $F4: xChr := #$AF;
              $F5: xChr := #$BF;
              $F6: xChr := #$A1;
              $F7: xChr := #$A2;
              $F8: xChr := #$B0;
              $F9: xChr := #$95;
              $FA: xChr := #$B7;
              $FB: xChr := #$AC;
              $FC: xChr := #$B9;
              $FD: xChr := #$A4;
            end;
      NStr := NStr + xChr;
    end;
  Str := NStr;
end;

procedure TAnyCommandString.Windows1251ToOEM866(var Str: string);
const
  Ap: Byte = ($C0 - $80);
  rya: Byte = ($F0 - $E0);
var
  iFor, xL: integer;
  GStr, NStr, xChr: string;
  xCh: Char;
begin
  NStr := '';
  GStr := Str;
  xL := length(GStr);
  for iFor := 1 to xL do
    begin
      xChr := #$20;
      xCh := GStr[iFor];
      if (xCh >= #$00) and (xCh <= #$7F) then {Первая часть без изменений}
        xChr := xCh
      else
        if (xCh >= #$C0) and (xCh <= #$EF) then
          xChr := chr(ord(xCh) - Ap)
        else
          if (xCh >= #$F0) and (xCh <= #$FF) then
            xChr := chr(ord(xCh) - rya)
          else
            case ord(xCh) of
              $82: xChr := #$2C;
              $84: xChr := #$22;
              $93: xChr := #$22;
              $94: xChr := #$22;
              $AB: xChr := #$22;
              $BB: xChr := #$22;
              $85: if xL < 254 then xChr := #$2E#$2E#$2E
                   else xChr := #$2E;
              $8B: xChr := #$3C;
              $9B: xChr := #$3E;
              $91: xChr := #$27;
              $92: xChr := #$27;
              $95: xChr := #$F9;
              $96: xChr := #$C4;
              $97: xChr := #$C4;
              $A1: xChr := #$F6;
              $A2: xChr := #$F7;
              $A3: xChr := #$4A;
              $A4: xChr := #$FD;
              $A6: xChr := #$7C;
              $A8: xChr := #$F0;
              $A9: xChr := #$B0;
              $AA: xChr := #$F2;
              $AC: xChr := #$FB;
              $AD: xChr := #$2D;
              $AE: xChr := #$C1;
              $AF: xChr := #$F4;
              $B0: xChr := #$F8;
              $B2: xChr := #$49;
              $B3: xChr := #$69;
              $B5: xChr := #$B2;
              $B7: xChr := #$FA;
              $B8: xChr := #$F1;
              $B9: xChr := #$FC;
              $BA: xChr := #$F3;
              $BC: xChr := #$6A;
              $BD: xChr := #$53;
              $BE: xChr := #$73;
              $BF: xChr := #$F5;
            end;
      NStr := NStr + xChr;
    end;
  Str := NStr;
end;

end.

