Problem with Delphi 2009 and old-style object type

I have a lot of older code that uses the old-style pascal object type that I am trying to work in Delphi 2009. It compiles, but there seem to be some problems with virtual methods. It seems that this issue has already been in Quality Central reports:

http://qc.embarcadero.com/wc/qcmain.aspx?d=71723

I was hoping that anyone who still uses them (perhaps PatrickvL?) Could get more information. We have LOTS of code that uses objects, and if this is not fixed, we are stuck. Thanks in advance!

+3
source share
4 answers

Embarcadero Quality Central. , , ... -. , , , , , Delphi 2009.

, , , : - (

+2

, , . , Delphi, .

, , . , . .

14 1994 , Delphi. . .

+6

, , , :) . , , . VMT.

VMT , . , - , VMT . , , , D2009. , , , , ...

Type
  PObject1 = ^TObject1;
  TObject1 = Object
    Magic: Array[0..3] of Byte; //or integer or whatever I was playing with the size
    FCount     : Integer;
    Constructor Init;
    Procedure Add; virtual; 
    Procedure Deduct; virtual; 
    end;

Type
  PObject2   = ^TObject2;
  TObject2   = Object(TObject1)
    Constructor Init;
    end;

:

.
.
.
Object2^.Add;
Object2^.Deduct;

proc, , 2- :)

, , ^ 2009, : (

- . BASE. , / Grep... .

+3

- , - .... D2009 ? /?

:

---------------

program testD2009;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Object1U in 'Object1U.pas',
  Object2U in 'Object2U.pas';


Var
  Object1 : PObject1;
  Object2 : PObject2;
begin
  try
    Object1 := New(PObject1,Init);
    Object1^.Add;
    Object1^.Deduct;

    Object2 := New(PObject2,Init);
    Object2^.Add;
    Object2^.Deduct;
    readln;
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.

-------------- Object1

unit Object1U;

interface

uses SysUtils;

Type
  PObject1 = ^TObject1;
  TObject1 = Object
    Magic: Array[0..3] of Byte;
    FCount     : Integer;
    Constructor Init;
    Procedure Add; virtual; { removing virtual allows the program to run }
    Procedure Deduct; virtual; { removing virtual allows the program to run }
    end;

implementation


Procedure TObject1.Add;
begin
  Writeln('Object1 Add');
end;

procedure TObject1.Deduct;
begin
  Writeln('Object1 Deduct');
end;

Constructor TObject1.Init;
begin
  inherited;
  FCount      := 0;
  Writeln('TObject1 Init');
end;

end.

---------------- 2

unit Object2U;

interface

uses Object1U;

Type
  PObject2   = ^TObject2;
  TObject2   = Object(TObject1)
    Constructor Init;
    Procedure Add; virtual; { removing virtual allows the program to run }
    Procedure Deduct; virtual; { removing virtual allows the program to run }
   end;

implementation

procedure TObject2.Add;
begin
  Writeln('Object2 Add');
  inherited;
end;

procedure TObject2.Deduct;
begin
  Writeln('Object2 Deduct');
  inherited;
end;

Constructor TObject2.Init;
begin
  Inherited Init;
  fCount := 1;
  Writeln('TObject2:Init');
end;

end.

---------------- :

TObject1 Init
Object1 Add
Object1 Deduct
TObject1 Init
TObject2: Init
Object2 Add
Object1 Add
Object2 Deduct
Object1 Deduct

I am puzzled :).

+3
source

Source: https://habr.com/ru/post/1710784/


All Articles