Einzelnen Beitrag anzeigen

Der_Unwissende

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

Re: Java to pascal/delphi

  Alt 24. Jun 2006, 11: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