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 2 von 2     12   
pastra

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

Re: HELP: JAVA TO PASCAL/DELPHI

  Alt 24. Jun 2006, 10:50
Hi s.h.a.r.k!

Thanks for translating the code, I am about to test it now....


You wrote: j := 1; // Index in a String is different - in Delphi it starts with 1

i fixed it like this: while j <= i do otherwise the last char didn't get processed..

I will return later and tell you how it is going..


For now BIG thanks and by the way, I really think this forum "ROX"



Chears 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
 
#12

Re: Java to pascal/delphi

  Alt 24. Jun 2006, 11:42
Zitat:
i fixed it like this: while j <= i do otherwise the last char didn't get processed..
Oh, sorry, but the it has to work fine!
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
Der_Unwissende

Registriert seit: 13. Dez 2003
Ort: Berlin
1.756 Beiträge
 
#13

Re: Java to pascal/delphi

  Alt 24. Jun 2006, 12:02
Hi,
I think there are some little mistakes you should fix.
First of all, you don't need any kind of StringBuffer in Delphi. To Java a String is just a static class and each assignment will create a new instance (and the GC have to free the old unused one). Therefore a buffer (no fixed size) encapsulates the functianality of working with strings that are supposed to change there size.
Although this is next to the Delphi-behaviour working with Strings you know how many characters are used in your string and you can allocate this memory before returning the string (of cause you can use the TStringList, but no need to do so!)

Lets have a look at this part
Delphi-Quellcode:
if c = '&then
begin
  if (i < j+5) then
  begin
    break;
  end;

  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
Well there is something missing, don't you think? Although k is changed, no one will ever know. And Java does automaticaly cast a single Character into a short value, that does not mean, that the string will be casted into the represented value (StrToInt) but the byte value of this string (e.g. A = 65).
Just change the sourcelines to

Delphi-Quellcode:
if c = '&then
begin
  if (i < j+5) then
  begin
    break;
  end;

  k := 0;
  for l := 0 to 3 do
  begin
    inc(j);
    k := k*16;
    k := k + ord(s[j]) - 65; // Here you habe to be careful! The character here must be a number!
  end;
  
  buffer.append(chr(k));
end
Regards Der Unwissende
  Mit Zitat antworten Zitat
pastra

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

Re: Java to pascal/delphi

  Alt 25. Jun 2006, 14:25
Hi again, thanks it works now. Yes I see what you meen by + ord(s[j])..

Thanks!
  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 01:03 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