Einzelnen Beitrag anzeigen

Furtbichler
(Gast)

n/a Beiträge
 
#4

AW: Ini-Einstellung umwandeln für Komponente

  Alt 11. Mär 2012, 08:32
Converterklassen bauen.

Delphi-Quellcode:
uses StrUtils;

Type
  TParityConverter = Class
  Private
    Class Const
      ParitySettings = Array [paEven..paSpace] Of String = ('even','mark','odd','space');
  Public
    Class Function FromString (setting : String) : TParity;
    Class Function ToString (setting : TParity) : String;
  End;

Class Function TParityConverter.FromString (setting : String) : TParity;
Var
  p : Integer;

Begin
  p := IndexText (setting, ParitySettings);
  if p=-1 then
    Raise EConvertException.CreateFmt('Unknown parity setting %s', [setting])
  else
    result := TParity(p);
End;

Class Function TParityConverter.ToString (setting : TParity) : String;
Begin
  Try
    Result := ParritySettings[Ord(setting)];
  Except
    Raise EConvertException.CreateFmt('Invalid parity (%d)',[setting]);
  End
End;
  Mit Zitat antworten Zitat