program Calculus;
uses graph,
      mx;
var grDriver : Integer;
    grMode   : Integer;

    measuresList : mxListBox;
    leftList : mxListBox;
    inputBox : mxInpTextBox;
    labelBox : mxRealLabel;

    measure : Longint;
    type1   : Longint;
    type2   : Longint;
    temp    : string[50];
    temp2   : string[50];
    number  : Longint;
    result  : Real;

function Convert( mes, t1, t2, num : Longint ): Real;
var res : Real;
    tem : Longint;
begin
     case mes of
          1: begin
            case t1 of
                 1: tem := num;
                 2: tem := 10*num;
                 3: tem := 1000*num;
                 4: tem := 1000000*num;
            end;
            case t2 of
                 1: res := tem;
                 2: res := tem/10;
                 3: res := tem/1000;
                 4: res := tem/1000000;
            end;
          end;
          2: begin
             case t1 of
                  1: tem := num;
                  2: tem := 100*num;
                  3: tem := 1000000*num;
                  4: tem := 100000000*num;
             end;
             case t2 of
                  1: res := tem;
                  2: res := tem/100;
                  3: res := tem/1000000;
                  4: res := tem/100000000;
             end;
          end;
          3: begin
             case t1 of
                  1: tem := num;
                  2: tem := 1000*num;
                  3: tem := 1000000*num;
                  4: tem := 1000000000*num;
             end;
             case t2 of
                  1: res := tem;
                  2: res := num/1000;
                  3: res := num/1000000;
                  4: res := num/1000000000;
             end;

          end;
     end;
     Convert := res;
end;

begin
    grDriver := Detect;
    InitGraph(grDriver, grMode, '' );

    mx_Init_ListBox( measuresList );
     measuresList.text[1] := 'Length';
     measuresList.text[2] := 'Square';
     measuresList.text[3] := 'Volume';
     measuresList.UsedList := 3;
    mx_Execute_ListBox( measuresList, 'Measures:' );
    measure := measuresList.selected;

    mx_Init_ListBox( leftList );
    if measure = 1 then begin
       leftList.text[1] := 'mm';
       leftList.text[2] := 'sm';
       leftList.text[3] := 'm';
       leftList.text[4] := 'km';
       leftList.UsedList := 4;
       mx_Execute_ListBox( leftList, 'Length from :' );
       type1 := leftList.selected;
       case type1 of
            1: temp := 'mm';
            2: temp := 'sm';
            3: temp := 'm';
            4: temp := 'km';
       end;
       leftList.selected := 1;
       mx_Execute_ListBox( leftList, 'Length from '+ temp + ' to:' );
       type2 := leftList.selected;
       case type2 of
            1: temp2 := 'mm';
            2: temp2 := 'sm';
            3: temp2 := 'm';
            4: temp2 := 'km';
       end;
       mx_Init_InpTextBox( inputBox );
       mx_Execute_InpTextBox( inputBox, 'Length from ' + temp + ' to ' + temp2 );
       number := inputBox.text;
       result := Convert( measure, type1, type2, number );
       mx_Init_RealLabel( labelBox );
       labelBox.data := result;
       mx_Execute_RealLabel( labelBox, 'Length in '+temp2 )
    end;
    if measure = 2 then begin
       leftList.text[1] := 'mm*mm';
       leftList.text[2] := 'sm*sm';
       leftList.text[3] := 'm*m';
       leftList.text[4] := 'a';
       leftList.UsedList := 4;
       mx_Execute_ListBox( leftList, 'Square from :' );
       type1 := leftList.selected;
       case type1 of
            1: temp := 'mm*mm';
            2: temp := 'sm*sm';
            3: temp := 'm*m';
            4: temp := 'a';
       end;
       leftList.selected := 1;
       mx_Execute_ListBox( leftList, 'Square from '+ temp + ' to:' );
       type2 := leftList.selected;
       case type2 of
            1: temp2 := 'mm*mm';
            2: temp2 := 'sm*sm';
            3: temp2 := 'm*m';
            4: temp2 := 'a';
       end;
       mx_Init_InpTextBox( inputBox );
       mx_Execute_InpTextBox( inputBox, 'Square from ' + temp + ' to ' + temp2 );
       number := inputBox.text;
       result := Convert( measure, type1, type2, number );
       mx_Init_RealLabel( labelBox );
       labelBox.data := result;
       mx_Execute_RealLabel( labelBox, 'Square in ' + temp2 )
    end;
    if measure = 3 then begin
       leftList.text[1] := 'mm*mm*mm';
       leftList.text[2] := 'sm*sm*sm';
       leftList.text[3] := 'litres';
       leftList.text[4] := 'm*m*m';
       leftList.UsedList := 4;
       mx_Execute_ListBox( leftList, 'Volume from :' );
       type1 := leftList.selected;
       case type1 of
            1: temp := 'mm*mm*mm';
            2: temp := 'sm*sm*sm';
            3: temp := 'litres';
            4: temp := 'm*m*m';
       end;
       leftList.selected := 1;
       mx_Execute_ListBox( leftList, 'Volume from '+ temp + ' to:' );
       type2 := leftList.selected;
       case type2 of
            1: temp2 := 'mm*mm*mm';
            2: temp2 := 'sm*sm*sm';
            3: temp2 := 'litres';
            4: temp2 := 'm*m*m';
       end;
       mx_Init_InpTextBox( inputBox );
       mx_Execute_InpTextBox( inputBox, 'Volume from ' + temp + ' to ' + temp2 );
       number := inputBox.text;
       result := Convert( measure, type1, type2, number );
       mx_Init_RealLabel( labelBox );
       labelBox.data := result;
       mx_Execute_RealLabel( labelBox, 'Volume in ' + temp2 )
    end;

end.