Delphi-PRAXiS
Seite 1 von 2  1 2      

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

pastra 23. Jun 2006 21:11


Java to pascal/delphi
 
:arrow: Hi, can anyone help me with this code written i java..

If you have the required knowledge, please help.!



I started translating this JAVA into pascal code:
Delphi-Quellcode:
public static String decodeString(String s)
    {
        return decodeString(new QStringBuffer(), s).toString();
    }

    public static QStringBuffer decodeString(QStringBuffer qstringbuffer, String s)
    {
        if(s == null)
            return qstringbuffer;
        int i = s.length();
        for(int j = 0; j < i; j++)
        {
            char c = s.charAt(j);
            if(c == '&')
            {
                if(i < j + 5)
                    break;
                int k = 0;
                for(int l = 0; l < 4; l++)
                {
                    j++;
                    k *= 16;
                    k += s.charAt(j) - 65;
                }

                qstringbuffer.append((char)k);
            } else
            {
                qstringbuffer.append(c);
            }
        }

        return qstringbuffer;
    }
>>>>>>>>>> And now my (poor) result in rewriting it, many og the for loops and stuff I DIDNT manedge to translate, but here goes:

Delphi-Quellcode:
function decodeString(String s)
begin
result:= decodeString(new QStringBuffer(), s).toString();
end;


    function QStringBuffer decodeString(QStringBuffer qstringbuffer, String s)
    var
    i,k,j,l:integer;
    c:char;
    qstringbuffer: Tstringlist;
    begin
        if(s == null)
        result:= qstringbuffer;
        i = length(s);

        for(j = 0; j < i; j++)
        begin
            c = s[j];
            if c ='&' then
            begin
                if(i < j + 5)
                    break;
                k = 0;
                for(l = 0; l < 4; l++)
                begin
                    j:=j+1;
                    k :=k*16;
                    k =k+s[j] - 65;
                end;

                qstringbuffer.append((char)k);
            end else
            begin
                qstringbuffer.append(c);
            end;
        end;

        result:= qstringbuffer;
    end;
>>> So How am I dooing so far?.. Any corrections, comments or hints?


Thanks in advance!

[b]Regars PasTra

s.h.a.r.k 23. Jun 2006 21:37

Re: HELP: JAVA TO PASCAL/DELPHI
 
First, try to use the BBCode of the Board. Use the [delphi]-Tag oder the [code]-Tag!

pastra 23. Jun 2006 21:41

Re: HELP: JAVA TO PASCAL/DELPHI
 
Zitat:

Zitat von s.h.a.r.k
First, try to use the BBCode of the Board. Use the [delphi]-Tag oder the [code]-Tag!


Sorry I did not realize that.


I have changed it now..


Any advices ideas to the snippers?

s.h.a.r.k 23. Jun 2006 22:14

Re: HELP: JAVA TO PASCAL/DELPHI
 
When you wait about ten minutes then i have a solution.

What makes exactly this code? Because i doesn't know how to program with Java ;)
Code:
return decodeString(new QStringBuffer(), s).toString();

pastra 23. Jun 2006 22:22

Re: HELP: JAVA TO PASCAL/DELPHI
 
Zitat:

Zitat von s.h.a.r.k
When you wait about ten minutes then i have a solution.

What makes exactly this code? Because i doesn't know how to program with Java ;)
Code:
return decodeString(new QStringBuffer(), s).toString();

Hi again, DecodeString is function that returns a string output from a given input after "altering it", I am NOT programming i JAVA so that is my problem aswell...

The way I see it Decodestring is called like like this:

var
s:string
begin
s:= DecodeString('Hello');
end;

mkinzler 23. Jun 2006 22:25

Re: HELP: JAVA TO PASCAL/DELPHI
 
Zitat:

What makes exactly this code? Because i doesn't know how to program with Java
It creates a new QStringBuffer and Casts it to a string.

inherited 23. Jun 2006 22:26

Re: HELP: JAVA TO PASCAL/DELPHI
 
LOL 'what makes this code' i think he 'makes' nothing. he is doing a lot ;)
My Java isn't good enough to translate, but here some tips for pascal-language:
to compare to variables, you use '=', e.g.
Delphi-Quellcode:
  if s1=s2 then whatever;
to assign a variable you use ':=', e.g

Delphi-Quellcode:
  s1:=s2;
Furthermore there is no
Code:
  l++
in delphi/pascal, to increase the value of an integer-var by 1, use
Delphi-Quellcode:
  i:=i+1;
or
Delphi-Quellcode:
  inc(i);
so far
inh3r1ted

s.h.a.r.k 23. Jun 2006 22:45

Re: HELP: JAVA TO PASCAL/DELPHI
 
Try this code - there is no guaranty that it's right :thumb:
Delphi-Quellcode:
function decodeStringF2(QStringBuffer : TStringList; s: String): TStringList;
var
  i, k, j, l : Integer;
  c : Char;
  Buffer : TStringList;
begin
  Buffer := QStringBuffer;

  if(s <> '') then
  begin
    i := length(s);

    // i had to replace the for because i can't change an counter in a for
    j := 1; // Index in a String is different - in Delphi it starts with 1
    while j < i do
    begin
      c := s[j];
      if c = '&' then
      begin
        if (i < j+5) then break;

        k := 0;
        for l := 0 to 3 do
        begin
          inc(j);
          k := k*16;
          k := k + StrToInt(s[j]) - 65; // Here you habe to be careful! The character here must be a number!
        end;
      end
      else begin
        Buffer.Append(c);
      end;
      inc(j);
    end;
  end;

  Result := Buffer;
end;

function decodeStringF1(s: String): String;
var
  Buffer : TStringList;
begin
  Buffer := TStringList.Create;
  Buffer := decodeStringF2(Buffer, s);
  Result := Buffer.Text;
end;
// Edit
Deleted some test-code!

fkerber 23. Jun 2006 23:20

Re: HELP: JAVA TO PASCAL/DELPHI
 
Hi!

... and Welcome in DP!

I can't help you with your problem but I have a little request to you:
Could you please change the title of this topic? (simply edit your first post)
There a lot of people who are searching for help and so it's not necessary to say "help"! Furthermore the title is easier to read if it's not UPPERCASE!

Thank you!


Ciao Frederic

pastra 24. Jun 2006 09:47

Re: HELP: JAVA TO PASCAL/DELPHI
 
Zitat:

Zitat von fkerber
Hi!

... and Welcome in DP!

I can't help you with your problem but I have a little request to you:
Could you please change the title of this topic? (simply edit your first post)
There a lot of people who are searching for help and so it's not necessary to say "help"! Furthermore the title is easier to read if it's not UPPERCASE!

Thank you!


Ciao Frederic



I have changed it now..


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:04 Uhr.
Seite 1 von 2  1 2      

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