Einzelnen Beitrag anzeigen

Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.545 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: For-loop from C to Delphi

  Alt 18. Sep 2011, 17:25
Since we cannot know the type of Data, here are 2 suggestions:
Delphi-Quellcode:
//If Data is a string:
i := 1;
while i < Length(Data) do

//If Data is a dynamic array of Char:
i := 0;
while i < High(Data) do

//Anyway, I hope this is right in both cases:
  begin
    if Data[i] = 'Xthen
      raise Exception.Create('Invalid position of X in Telepen data');
    if Data[i + 1] = 'Xthen
      Count := Count + Ord(Data[i]) + 17
    else
      Count := Count + 27 + (Ord(Data[i]) * 10) + Ord(Data[i + 1]);
    inc(i, 2);
  end;
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat