Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   java to delphi (https://www.delphipraxis.net/129814-java-delphi.html)

pastra 26. Feb 2009 02:50


java to delphi
 
I am trying to translate this java code to delphi:

Delphi-Quellcode:
String FlashG(int fromINT, int toINT)
    {
        StringBuffer stringbuffer = new StringBuffer();
        int PPP;
        for(PPP = toINT; PPP < fromINT; PPP *= toINT);
        do
        {
            int OOP = fromINT / PPP;
            char COMP = (char)(LEVEL + OOP);
            stringbuffer.append(COMP);
            fromINT -= PPP * OOP;
            PPP /= toINT;
        } while(PPP > 0);
        return stringbuffer.toString();
    }


LEVEL = 'K';

It goes fine to the point of the for loop. Can't figure it out.. PPP is changed in the for loop?

If anyone can translate it, it will be greatly appreciated.

Cheers


Regards PasTra

jaenicke 26. Feb 2009 03:11

Re: java to delphi
 
As you didn't tell what the code is for I couldn't test it. A direct translation should be:
Delphi-Quellcode:
function FlashG(fromINT, toINT: Integer): String;
var
  PPP, OOP: Integer;
begin
  Result := '';
  PPP := toINT;
  while PPP < fromInt do
    PPP := PPP * toINT;
  repeat
    OOP := fromInt div PPP;
    Result := Result + Chr(Ord('K') + OOP);
    fromInt := fromInt - PPP * OOP;
    PPP := PPP div toInt;
  until PPP <= 0;
end;
The naming conventions are different in Delphi but I didn't change it.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:46 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