AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

For-loop from C to Delphi

Ein Thema von WojTec · begonnen am 18. Sep 2011 · letzter Beitrag vom 19. Sep 2011
Antwort Antwort
Seite 2 von 2     12   
Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#11

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:24
Easy to forget, since Union seemed to use a zero base on Strings, which can lead to quite some confusion - I know that first hand, since I regularly forget it myself. But you're right of course
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 
#12

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:30
Yes this was for PChar (see StrCopy). But the principle was to show the StrToInt() and Ord() function's results.
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:41
I tried to translate the two posted functions:
Delphi-Quellcode:
function ctoi(source: char): integer;
begin
  if (source >= '0') and (source <= '9') then
    Result := Ord(source) - Ord('0')
  else
    Result := Ord(source) - Ord('A') + 10;
end;

function itoc(source: integer): char;
begin
  if (source >= 0) and (source <= 9) then
    Result := Chr(Ord('0') + source)
  else
    Result := Chr(Ord('A') + source - 10);
end;
Untested, use at your own risk.
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
Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 
#14

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 12:56
Oder kürzer Or shorter:
Delphi-Quellcode:
function ctoi(source: char): integer;
begin
   result := StrToInt('$'+source);
end;

function itoc(source: integer): char;
begin
   c := Format('%x', [source])[1];
end;
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 13:00
And what about ctoi('Z')?
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
Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 
#16

AW: For-loop from C to Delphi

  Alt 19. Sep 2011, 13:32
Ok, my solution works only for hex
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:10 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz