Ver Mensaje Individual
  #16  
Antiguo 05-12-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Daniel,

Cita:
Empezado por ecfisa
...conviene abstenerse de incluir métodos virtuales cuando se usa el antiguo estilo Pascal...trae aparejado problemas que ya han sido reportados en QualityCentral...


Revisa este código:
Código Delphi [-]
 
  program testD2009;
  
  {$APPTYPE CONSOLE}
  
  uses
    SysUtils;
  
  Type
    PObject1 = ^TObject1;
    TObject1 = Object
      FCount     : Integer;
      Constructor Init;
      Procedure Add; virtual; { removing virtual allows the program to run }
      end;
  
  Type
    PObject2   = ^TObject2;
    TObject2   = Object(TObject1)
      Constructor Init;
      end;
  
  Constructor TObject1.Init;
  begin
  { Commenting out this assignment allows the program to run.
    It also runs if Procedure Add; is not Virtual.
    I presume there is some address mismatch resulting in an
    over-write of the VMT }
  FCount := 0;
  Writeln('TDynArray:Init');
  end;
  
  Procedure TObject1.Add;
  begin
  Writeln('Add');
  end;
  
  Constructor TObject2.Init;
  begin
  Inherited Init;
  Writeln('TObject2:Init');
  end;
  
  Var
    Object1 : PObject1;
    Object2 : PObject2;
  begin
    try
      Object1 := New(PObject1,Init);
      Object1^.Add;
  
      Object2 := New(PObject2,Init);
      Object2^.Add;
      readln;
    except
      on E:Exception do
        Writeln(E.Classname, ': ', E.Message);
    end;
  end.
Tomado de : QualityCentral-Using old style Objects in D2009 fails

El código anterior que falla en Delphi 2009 según se indica en QualityCentral, funciona correctamente en Delphi 2010 y Delphi XE6 sobre Windows x32 y Delphi XE7 sobre Windows 10 Technical Preview x32, al parecer el problema reportado solo aplica a Delphi 2009, no obstante para desarrollos formales orientados a objetos se debe usar el tipo Class.

Espero sea útil

Nelson.
Responder Con Cita