[fpc-devel] Found two Delphi incompatibilities

Sergei Gorelkin sergei_gorelkin at mail.ru
Thu Aug 31 09:00:14 CEST 2006


Hello,

While porting some Delphi code, I found the following two
incomatibility issues. Should I report them as bugs?

Sample 1: It compiles both in Delphi and FPC, but FPC executable fails
at runtime. Delphi inserts temporary string variable and conversion
(array of char -> string), but FPC treats the pointer literally.
-----
const
  TestData: array[0..7] of Char = 'abc'#10'def'#0;

procedure Test1;
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  sl.Text := string(@TestData[0]);  // <- fails here
  sl.Free;
end;
-----

Sample 2: This one compiles with Delphi (again, it inserts necessary
conversion Wide -> Ansi), but does not compile with FPC, neither in
objfpc nor in Delphi mode.

-----
function Test2: string;
var
  buf: array[0..255] of char;
  len: Integer;
begin
{ (skipped) I read USB string descriptor into buf. After that,
  buf[0] contains length of descriptor in bytes, buf[1] = 3,
  and rest is filled with Unicode chars. Now I want to convert it into
  ASCII...
}
  len := Integer(buf[0]) shr 1;
  SetString(result, PWideChar(@buf[2]), len-1);
end;
-----

Best regards,
 Sergei





More information about the fpc-devel mailing list