unit zipcode_unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, ComCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    Memo1: TMemo;
    GroupBox2: TGroupBox;
    BitBtn1: TBitBtn;
    Memo2: TMemo;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    StaticText5: TStaticText;
    StaticText6: TStaticText;
    GroupBox3: TGroupBox;
    StatusBar1: TStatusBar;
    StringGrid1: TStringGrid;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    StaticText7: TStaticText;
    Edit1: TEdit;
    StaticText8: TStaticText;
    BitBtn5: TBitBtn;
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  inputtext,outputtext:string;
  size:word;
  charactercounter:array[1..32]of word;

implementation

{$R *.dfm}

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  Memo1.Clear;
end;

procedure TForm1.BitBtn4Click(Sender: TObject);

var
  changed, behind:boolean;
  i:word;
  
begin
  outputtext:='';
  Memo2.Clear;
  BitBtn2.Enabled:=true;
  BitBtn4.Enabled:=false;
  size:=Length(Memo1.Text);
  if size>0
  then
  begin
    inputtext:=Memo1.Text;
    //Memo1.Clear;
    i:=1;
    inputtext[i]:=UpCase(inputtext[i]);
    while behind=false do
    begin                 //begin of while
      changed:=false;
      inputtext[i]:=UpCase(inputtext[i]);
      if (not(inputtext[i] in['0'..'9','','','','','','','A'..'Z','',' ',',','.',':','-','#']))
      then
      begin             //begin of if3
        delete(inputtext,i,1);
        changed:=true;
      end;              //end of if3
      if length(inputtext)>0
      then
      begin                  //begin of if sekundaer0
      case inputtext[i] of
        '0':
        begin           //begin of 0
          delete(inputtext,i,1);
          insert('NULL',inputtext,i);
          i:=i+3;
        end;            //end of 0
        '1':
        begin          //begin of 1
          delete(inputtext,i,1);
          insert('EINS',inputtext,i);
          i:=i+3;
        end;            //end of 1
        '2':
        begin           //begin of 2
          delete(inputtext,i,1);
          insert('ZWEI',inputtext,i);
          i:=i+3;
        end;            //end of 2
        '3':
        begin           //begin of 3
          delete(inputtext,i,1);
          insert('DREI',inputtext,i);
          i:=i+3;
        end;            //end of 3
        '4':
        begin           //begin of 4
          delete(inputtext,i,1);
          insert('VIER',inputtext,i);
          i:=i+3;
        end;            //end of 4
        '5':
        begin           //begin of 5
          delete(inputtext,i,1);
          insert('FUENF',inputtext,i);
          i:=i+4;
        end;            //end of 5
        '6':
        begin           //begin of 6
          delete(inputtext,i,1);
          insert('SECHS',inputtext,i);
          i:=i+4;
        end;            //end of 6
        '7':
        begin           //begin of 7
          delete(inputtext,i,1);
          insert('SIEBEN',inputtext,i);
          i:=i+5;
        end;            //end of 7
        '8':
        begin           //begin of 8
          delete(inputtext,i,1);
          insert('ACHT',inputtext,i);
          i:=i+3;
        end;            //end of 8
        '9':
        begin           //begin of 9
          delete(inputtext,i,1);
          insert('NEUN',inputtext,i);
          i:=i+3;
        end;            //end of 9
        '', '': begin      //begin of oe
          delete(inputtext,i,1);
          insert('OE',inputtext,i);
          i:=i+1;
        end;            //end of oe
        '', '': begin      //begin of ae
          delete(inputtext,i,1);
          insert('AE',inputtext,i);
          i:=i+1;
        end;            //end of ae
        '', '': begin      //begin of ue
          delete(inputtext,i,1);
          insert('UE',inputtext,i);
          i:=i+1;
        end;            //end of ue
        '': begin      //begin of ss
          delete(inputtext,i,1);
          insert('SZ',inputtext,i);
          i:=i+1;
        end;            //end of ss
      end;//end of case
      if changed=false
      then
      begin
        inc(i);
      end;{end of then}
      if i>Length(inputtext)
      then
      begin
        behind:=true;
      end;{end of then}
    end;//end of while
    Memo1.Text:=inputtext;{Text neu einschreiben}
    size:=Length(inputtext);
    Edit1.Text:=IntToStr(size);
    StatusBar1.Panels[1].Text:=IntToStr(size);
  end;//end of while
  end
  else
  begin
    with Application do
    begin
      NormalizeTopMosts;
      MessageBox('Die Eingabeseite darf nicht leer sein!', 'Achtung', MB_OK);
      RestoreTopMosts;
      BitBtn4.Enabled:=true;
    end;
  end;{end of else}
  for i:=1 to size do
  begin
    case inputtext[i] of
      ' ':
      inc(charactercounter[1]);
      'A':
      inc(charactercounter[2]);
      'B':
      inc(charactercounter[3]);
      'C':
      inc(charactercounter[4]);
      'D':
      inc(charactercounter[5]);
      'E':
      inc(charactercounter[6]);
      'F':
      inc(charactercounter[7]);
      'G':
      inc(charactercounter[8]);
      'H':
      inc(charactercounter[9]);
      'I':
      inc(charactercounter[10]);
      'J':
      inc(charactercounter[11]);
      'K':
      inc(charactercounter[12]);
      'L':
      inc(charactercounter[13]);
      'M':
      inc(charactercounter[14]);
      'N':
      inc(charactercounter[15]);
      'O':
      inc(charactercounter[16]);
      'P':
      inc(charactercounter[17]);
      'Q':
      inc(charactercounter[18]);
      'R':
      inc(charactercounter[19]);
      'S':
      inc(charactercounter[20]);
      'T':
      inc(charactercounter[21]);
      'U':
      inc(charactercounter[22]);
      'V':
      inc(charactercounter[23]);
      'W':
      inc(charactercounter[24]);
      'X':
      inc(charactercounter[25]);
      'Y':
      inc(charactercounter[26]);
      'Z':
      inc(charactercounter[27]);
      '.':
      inc(charactercounter[28]);
      ',':
      inc(charactercounter[29]);
      ':':
      inc(charactercounter[30]);
      '-':
      inc(charactercounter[31]);
      '#':
      inc(charactercounter[32]);
    end;
  end;//end of for
  for i:=1 to 32 do
  begin
    StringGrid1.Cells[2,i]:=IntToStr(charactercounter[i]);
  end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);

var
  i:word;

begin
  for i:=1 to 32 do
  begin
    charactercounter[i]:=0;
  end;
  BitBtn2.Enabled:=false;
  for i:=1 to size do
  begin
    Case inputtext[i] of
      ' ':
      begin
        outputtext:=outputtext+'00000';
      end;//end of ' '
      'A':
      begin
        outputtext:=outputtext+'00001';
      end;//end of 'A'
      'B':
      begin
        outputtext:=outputtext+'00010';
      end;//end of 'B'
      'C':
      begin
        outputtext:=outputtext+'00011';
      end;//end of 'C'
      'D':
      begin
        outputtext:=outputtext+'00100';
      end;//end of 'D'
      'E':
      begin
        outputtext:=outputtext+'00101';
      end;//end of 'E'
      'F':
      begin
        outputtext:=outputtext+'00110';
      end;//end of 'F'
      'G':
      begin
        outputtext:=outputtext+'00111';
      end;//end of 'G'
      'H':
      begin
        outputtext:=outputtext+'01000';
      end;//end of 'H'
      'I':
      begin
        outputtext:=outputtext+'01001';
      end;//end of 'I'
      'J':
      begin
        outputtext:=outputtext+'01010';
      end;//end of 'J'
      'K':
      begin
        outputtext:=outputtext+'01011';
      end;//end of 'K'
      'L':
      begin
        outputtext:=outputtext+'01100';
      end;//end of 'L'
      'M':
      begin
        outputtext:=outputtext+'01101';
      end;//end of 'M'
      'N':
      begin
        outputtext:=outputtext+'01110';
      end;//end of 'N'
      'O':
      begin
        outputtext:=outputtext+'01111';
      end;//end of 'O'
      'P':
      begin
        outputtext:=outputtext+'10000';
      end;//end of 'P'
      'Q':
      begin
        outputtext:=outputtext+'10001';
      end;//end of 'Q'
      'R':
      begin
        outputtext:=outputtext+'10010';
      end;//end of 'R'
      'S':
      begin
        outputtext:=outputtext+'10011';
      end;//end of 'S'
      'T':
      begin
        outputtext:=outputtext+'10100';
      end;//end of 'T'
      'U':
      begin
        outputtext:=outputtext+'10101';
      end;//end of 'U'
      'V':
      begin
        outputtext:=outputtext+'10110';
      end;//end of 'V'
      'W':
      begin
        outputtext:=outputtext+'10111';
      end;//end of 'W'
      'X':
      begin
        outputtext:=outputtext+'11000';
      end;//end of 'X'
      'Y':
      begin
        outputtext:=outputtext+'11001';
      end;//end of 'Y'
      'Z':
      begin
        outputtext:=outputtext+'11010';
      end;//end of 'Z'
      '.':
      begin
        outputtext:=outputtext+'11011';
      end;//end of '.'
      ',':
      begin
        outputtext:=outputtext+'11100';
      end;//end of ','
      ':':
      begin
        outputtext:=outputtext+'11101';
      end;//end of ':'
      '-':
      begin
        outputtext:=outputtext+'11110';
      end;//end of '-'
      '#':
      begin
        outputtext:=outputtext+'11111';
      end;//end of '#'
    end;//end of case
    Memo2.Text:=outputtext;
  end;
end;

procedure TForm1.BitBtn5Click(Sender: TObject);

var
  blocktext:string;
  i:word;

{Schaltet die Fnfergruppen ein und aus}
  
begin
  if BitBtn5.Caption = 'Fnfer-Gruppen schalten'
  then
  begin
    BitBtn5.Caption:='Blocktext';
    blocktext:=outputtext;
    i:=0;
    repeat
      inc(i);
      if i mod 6=0
      then
      begin
        insert(' ',blocktext,i);
        inc(size);
      end;
    until i=size;
    Memo2.Clear;
    Memo2.Text:=blocktext;
  end
  else
  begin
    BitBtn5.Caption:='Fnfer-Gruppen schalten';
    Memo2.Text:=outputtext;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);

var
  i:byte;

begin
  StringGrid1.Cells[0,0]:='Index';
  StringGrid1.Cells[1,0]:='Zeichen';
  StringGrid1.Cells[2,0]:='Anzahl';
  StringGrid1.Cells[3,0]:='Binr';
  for i:=1 to 33 do
  begin
    StringGrid1.Cells[0,i]:=IntToStr(i);
  end;
  for i:=2 to 28 do
  begin
    StringGrid1.Cells[1,i]:=chr(i+63);
  end;
  StringGrid1.Cells[1,1]:='SPACE';
  StringGrid1.Cells[1,28]:='.';
  StringGrid1.Cells[1,29]:=',';
  StringGrid1.Cells[1,30]:=':';
  StringGrid1.Cells[1,31]:='-';
  StringGrid1.Cells[1,32]:='#';

  StringGrid1.Cells[3,1]:='00000';
  StringGrid1.Cells[3,2]:='00001';
  StringGrid1.Cells[3,3]:='00010';
  StringGrid1.Cells[3,4]:='00011';
  StringGrid1.Cells[3,5]:='00100';
  StringGrid1.Cells[3,6]:='00101';
  StringGrid1.Cells[3,7]:='00110';
  StringGrid1.Cells[3,8]:='00111';
  StringGrid1.Cells[3,9]:='01000';
  StringGrid1.Cells[3,10]:='01001';
  StringGrid1.Cells[3,11]:='01010';
  StringGrid1.Cells[3,12]:='01011';
  StringGrid1.Cells[3,13]:='01100';
  StringGrid1.Cells[3,14]:='01101';
  StringGrid1.Cells[3,15]:='01110';
  StringGrid1.Cells[3,16]:='01111';
  StringGrid1.Cells[3,17]:='10000';
  StringGrid1.Cells[3,18]:='10001';
  StringGrid1.Cells[3,19]:='10010';
  StringGrid1.Cells[3,20]:='10011';
  StringGrid1.Cells[3,21]:='10100';
  StringGrid1.Cells[3,22]:='10101';
  StringGrid1.Cells[3,23]:='10110';
  StringGrid1.Cells[3,24]:='10111';
  StringGrid1.Cells[3,25]:='11000';
  StringGrid1.Cells[3,26]:='11001';
  StringGrid1.Cells[3,27]:='11010';
  StringGrid1.Cells[3,28]:='11011';
  StringGrid1.Cells[3,29]:='11100';
  StringGrid1.Cells[3,30]:='11101';
  StringGrid1.Cells[3,31]:='11110';
  StringGrid1.Cells[3,32]:='11111';
end;

end.
