Delphi-PRAXiS
Seite 2 von 2     12   

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 24. Jun 2006 09:50

Re: HELP: JAVA TO PASCAL/DELPHI
 
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

s.h.a.r.k 24. Jun 2006 10:42

Re: Java to pascal/delphi
 
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! ;)

Der_Unwissende 24. Jun 2006 11:02

Re: Java to pascal/delphi
 
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

pastra 25. Jun 2006 13:25

Re: Java to pascal/delphi
 
Hi again, thanks it works now. Yes I see what you meen by + ord(s[j])..

Thanks!


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