Thema: Delphi Einheiten parsen

Einzelnen Beitrag anzeigen

Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#14

AW: Einheiten parsen

  Alt 9. Mär 2015, 15:38
Kann man da nicht mit Sets oder irgendwie bitweise was rechen, sonst tippt man sich ja den Wolf? (und sind hier gerade mal 9 mögliche Kombinationen). Die usNone müssen natürlich noch ausgefüllt werden.

Delphi-Quellcode:

type
  TUnitStyle = (usNone, usKNdivM3, usKNdivM2, usKNdivM, usKNMdivM, usKNM, usKN, usM3, usM2, usM);

function GetUnitPlus(const A, B: TUnitStyle): TUnitStyle;
begin
  if A = B then
    Result := A
  else
    Result := usNone;
end;

function GetUnitMinus(const A, B: TUnitStyle): TUnitStyle;
begin
  if A = B then
    Result := A
  else
    Result := usNone;
end;

function GetUnitDiv(const A, B: TUnitStyle): TUnitStyle;
begin
  Result := usNone;
  case A of
    usKNdivM3:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNdivM2:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNdivM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNMdivM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKN:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usM3:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usM2:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
  end;
end;

function GetUnitMult(const A, B: TUnitStyle): TUnitStyle;
begin
  Result := usNone;
  case A of
    usKNdivM3:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNdivM2:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNdivM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNMdivM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKNM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usKN:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usM3:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usM2:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
    usM:
    begin
      case B of
        usKNdivM3:
          Result := usNone;
        usKNdivM2:
          Result := usNone;
        usKNdivM:
          Result := usNone;
        usKNMdivM:
          Result := usNone;
        usKNM:
          Result := usNone;
        usKN:
          Result := usNone;
        usM3:
          Result := usNone;
        usM2:
          Result := usNone;
        usM:
          Result := usNone;
      end;
    end;
  end;
end;

end.
  Mit Zitat antworten Zitat