AGB  ·  Datenschutz  ·  Impressum  







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

Java to pascal/delphi

Ein Thema von pastra · begonnen am 23. Jun 2006 · letzter Beitrag vom 25. Jun 2006
Antwort Antwort
Seite 1 von 2  1 2      
pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#1

Java to pascal/delphi

  Alt 23. Jun 2006, 21:11
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
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#2

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 21:37
First, try to use the BBCode of the Board. Use the [delphi]-Tag oder the [code]-Tag!
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#3

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 21:41
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?
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#4

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 22:14
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();
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#5

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 22:22
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;
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 22:25
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.
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von inherited
inherited

Registriert seit: 19. Dez 2005
Ort: Rosdorf
2.022 Beiträge
 
Turbo Delphi für Win32
 
#7

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 22:26
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.
  if s1=s2 then whatever; to assign a variable you use ':=', e.g

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

SWIM SWIM HUNGRY!
Neuer Blog: hier!
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#8

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 22:45
Try this code - there is no guaranty that it's right
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!
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
Benutzerbild von fkerber
fkerber
(CodeLib-Manager)

Registriert seit: 9. Jul 2003
Ort: Ensdorf
6.723 Beiträge
 
Delphi XE Professional
 
#9

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 23. Jun 2006, 23:20
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
Frederic Kerber
  Mit Zitat antworten Zitat
pastra

Registriert seit: 23. Jun 2006
21 Beiträge
 
#10

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 24. Jun 2006, 09:47
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..
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


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 06:26 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