Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi For-loop from C to Delphi (https://www.delphipraxis.net/163176-loop-c-delphi.html)

Medium 19. Sep 2011 12:24

AW: For-loop from C to Delphi
 
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 :)

Union 19. Sep 2011 12:30

AW: For-loop from C to Delphi
 
Yes this was for PChar (see StrCopy). But the principle was to show the StrToInt() and Ord() function's results.

DeddyH 19. Sep 2011 12:41

AW: For-loop from C to Delphi
 
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.

Union 19. Sep 2011 12:56

AW: For-loop from C to Delphi
 
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;

DeddyH 19. Sep 2011 13:00

AW: For-loop from C to Delphi
 
And what about ctoi('Z')?

Union 19. Sep 2011 13:32

AW: For-loop from C to Delphi
 
Ok, my solution works only for hex :(


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:10 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz