Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Error "Incompatible types" al pasar de Delphi 2007 a Delphi Berlin (https://www.clubdelphi.com/foros/showthread.php?t=91502)

newtron 20-02-2017 20:01:09

Error "Incompatible types" al pasar de Delphi 2007 a Delphi Berlin
 
Hola a tod@s.

Pasando un pequeño proyecto de Delphi 2007 a Delphi Berlín me encuentro el problema que en una línea me da el error "E2008 Incompatible types" al compilar, imagino que tendrá una solución tonta pero no doy con la tecla.

El código es el siguiente:

Código Delphi [-]
function TAsBarcode.Code_39:string;

type TCode39 =
  record
    c : char;
    data : array[0..9] of char;
    chk: shortint;
  end;

const tabelle_39: array[0..43] of TCode39 = (
  ( c:'0'; data:'505160605'; chk:0 ),
  ( c:'1'; data:'605150506'; chk:1 ),
  ( c:'2'; data:'506150506'; chk:2 ),
  ( c:'3'; data:'606150505'; chk:3 ),
  ( c:'4'; data:'505160506'; chk:4 ),
  ( c:'5'; data:'605160505'; chk:5 ),
  ( c:'6'; data:'506160505'; chk:6 ),
  ( c:'7'; data:'505150606'; chk:7 ),
  ( c:'8'; data:'605150605'; chk:8 ),
  ( c:'9'; data:'506150605'; chk:9 ),
  ( c:'A'; data:'605051506'; chk:10),
  ( c:'B'; data:'506051506'; chk:11),
  ( c:'C'; data:'606051505'; chk:12),
  ( c:'D'; data:'505061506'; chk:13),
  ( c:'E'; data:'605061505'; chk:14),
  ( c:'F'; data:'506061505'; chk:15),
  ( c:'G'; data:'505051606'; chk:16),
  ( c:'H'; data:'605051605'; chk:17),
  ( c:'I'; data:'506051605'; chk:18),
  ( c:'J'; data:'505061605'; chk:19),
  ( c:'K'; data:'605050516'; chk:20),
  ( c:'L'; data:'506050516'; chk:21),
  ( c:'M'; data:'606050515'; chk:22),
  ( c:'N'; data:'505060516'; chk:23),
  ( c:'O'; data:'605060515'; chk:24),
  ( c:'P'; data:'506060515'; chk:25),
  ( c:'Q'; data:'505050616'; chk:26),
  ( c:'R'; data:'605050615'; chk:27),
  ( c:'S'; data:'506050615'; chk:28),
  ( c:'T'; data:'505060615'; chk:29),
  ( c:'U'; data:'615050506'; chk:30),
  ( c:'V'; data:'516050506'; chk:31),
  ( c:'W'; data:'616050505'; chk:32),
  ( c:'X'; data:'515060506'; chk:33),
  ( c:'Y'; data:'615060505'; chk:34),
  ( c:'Z'; data:'516060505'; chk:35),
  ( c:'-'; data:'515050606'; chk:36),
  ( c:'.'; data:'615050605'; chk:37),
  ( c:' '; data:'516050605'; chk:38),
  ( c:'*'; data:'515060605'; chk:0 ),
  ( c:'$'; data:'515151505'; chk:39),
  ( c:'/'; data:'515150515'; chk:40),
  ( c:'+'; data:'515051515'; chk:41),
  ( c:'%'; data:'505151515'; chk:42)
  );


function FindIdx(z:char):integer;
var
  i:integer;
begin
  for i:=0 to High(tabelle_39) do
  begin
    if z = tabelle_39[i].c then
    begin
      result := i;
      exit;
    end;
  end;
  result := -1;
end;

var
  i, idx : integer;
  checksum:integer;

begin
  checksum := 0;
  {Startcode}
  result := tabelle_39[FindIdx('*')].data + '0';   // ------------------------> Línea donde da el error

  for i:=1 to Length(FText) do
  begin
    idx := FindIdx(FText[i]);
    if idx < 0 then
      continue;
    result := result + tabelle_39[idx].data + '0';
    Inc(checksum, tabelle_39[idx].chk);
  end;

  {Calculate Checksum Data}
  if FCheckSum then
    begin
    checksum := checksum mod 43;
    for i:=0 to High(tabelle_39) do
      if checksum = tabelle_39[i].chk then
      begin
        result := result + tabelle_39[i].data + '0';
        break;
      end;
    end;

  {Stopcode}
  result := result + tabelle_39[FindIdx('*')].data;
end;

Si algún amable forero me indica qué tengo que cambiar lo agradeceré.

Gracias y un saludo

AgustinOrtu 20-02-2017 23:47:01

Edito: Mi respuesta era incorrecta :o

AgustinOrtu 21-02-2017 00:03:27

Solo encontre dos posibilidades:

1. Usar TStringBuilder:

Código Delphi [-]
var
  Builder: TStringBuilder;
  s: string;
  Chars: array [0..9] of Char;
begin
  Chars := 'ClubDelph';
  Builder := TStringBuilder.Create;
  try
    Builder.Append(Chars);
    Builder.Append('i');
    s := Builder.ToString;
  finally
    Builder.Free;
  end;

  Writeln(s);
  Readln;
end.

2. Mas sencillo, usar System.WideCharToString

Código Delphi [-]
begin
  Chars := 'ClubDelph';
  s := WideCharToString(Chars) + 'i';
  Writeln(s);
  Readln;
end.

En algun momento se habran deprecado los array of Char estaticos (hace muchisimo que no veo codigo escrito asi)

newtron 21-02-2017 12:30:35

Cita:

Empezado por AgustinOrtu (Mensaje 513519)
...
2. Mas sencillo, usar System.WideCharToString

Código Delphi [-]begin Chars := 'ClubDelph'; s := WideCharToString(Chars) + 'i'; Writeln(s); Readln; end.


En algun momento se habran deprecado los array of Char estaticos (hace muchisimo que no veo codigo escrito asi)

Estupendo, esto me resuelve el programa.

Gracias y un saludo

TOPX 21-02-2017 13:46:59

En mi ignorancia, lo hubiera hecho así:

Código Delphi [-]
  result := tabelle_39[FindIdx('*')].data;
  result := result + '0';
-


La franja horaria es GMT +2. Ahora son las 14:45:45.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi