Einzelnen Beitrag anzeigen

jbg

Registriert seit: 12. Jun 2002
3.481 Beiträge
 
Delphi 10.1 Berlin Professional
 
  Alt 27. Jul 2002, 16:30
Na da kenne ich eine Lösung mit weniger Programmieraufwand.
Delphi-Quellcode:
function CaseStringOf(const Value: string; const Args: array of string): string;
begin
  for Result := High(Args) downto 0 do
    if Value = Args[Result] then Break;
end;
Und das ganze case-insensitive:
Delphi-Quellcode:
function CaseStringIOf(const Value: string; const Args: array of string): string;
begin
  for Result := High(Args) downto 0 do
    if CompareText(Value, Args[Result]) = 0 then Break;
end;
Diese ist
1. Schneller, da nicht die RTTI benötigt wird
2. Einfache zu handhaben:
Delphi-Quellcode:
case CaseStringOf(S, ['Str1', 'Str2', 'Str3']) of
  0: // Str1
  1: // Str2
  2: // Str3
  else ...
end;
  Mit Zitat antworten Zitat