Hi all
Hi all,
I am trying to make a certain piece of code cross compile between Delphi and FPC.
On FPC, it compiles fine but on Delphi I get a [dcc32 Error] Project1.dpr(14): E2086 Type 'TAutoPtr' is not yet completely defined on Line 14.
Below is the relevant code.
program Project1;
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF FPC}
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TAutoPtr = record
private type
__TAutoPtr_T = TAutoPtr;
__PAutoPtr_T = ^__TAutoPtr_T;
TGuard = class(TInterfacedObject)
private
FOwner: __PAutoPtr_T;
public
constructor Create(AAutoPtrRec: __PAutoPtr_T);
destructor Destroy; override;
end;
private
FGuardian: IInterface;
FPointer: Pointer;
class procedure Initialize(var AAutoPtr: __TAutoPtr_T); static;
class procedure Finalize(var AAutoPtr: __TAutoPtr_T); static;
function GetPointer: Pointer; inline;
procedure SetPointer(Ptr: Pointer); overload; inline;
function GetObject: TObject; inline;
procedure SetObject(const AnObject: TObject); overload; inline;
function GetValue: T; inline;
procedure SetValue(const AValue: T); overload; inline;
procedure CheckGuard; inline;
end;
{ TAutoPtr.TGuard }
constructor TAutoPtr.TGuard.Create(AAutoPtrRec: __PAutoPtr_T);
begin
end;
destructor TAutoPtr.TGuard.Destroy;
begin
inherited;
end;
{ TAutoPtr }
procedure TAutoPtr.CheckGuard;
begin
end;
class procedure TAutoPtr.Finalize(var AAutoPtr: __TAutoPtr_T);
begin
end;
function TAutoPtr.GetObject: TObject;
begin
end;
function TAutoPtr.GetPointer: Pointer;
begin
end;
function TAutoPtr.GetValue: T;
begin
end;
class procedure TAutoPtr.Initialize(var AAutoPtr: __TAutoPtr_T);
begin
end;
procedure TAutoPtr.SetObject(const AnObject: TObject);
begin
end;
procedure TAutoPtr.SetPointer(Ptr: Pointer);
begin
end;
procedure TAutoPtr.SetValue(const AValue: T);
begin
end;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
I am trying to make a certain piece of code cross compile between Delphi and FPC.
On FPC, it compiles fine but on Delphi I get a [dcc32 Error] Project1.dpr(14): E2086 Type 'TAutoPtr
Below is the relevant code.
program Project1;
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF FPC}
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TAutoPtr
private type
__TAutoPtr_T = TAutoPtr
__PAutoPtr_T = ^__TAutoPtr_T;
TGuard = class(TInterfacedObject)
private
FOwner: __PAutoPtr_T;
public
constructor Create(AAutoPtrRec: __PAutoPtr_T);
destructor Destroy; override;
end;
private
FGuardian: IInterface;
FPointer: Pointer;
class procedure Initialize(var AAutoPtr: __TAutoPtr_T); static;
class procedure Finalize(var AAutoPtr: __TAutoPtr_T); static;
function GetPointer: Pointer; inline;
procedure SetPointer(Ptr: Pointer); overload; inline;
function GetObject: TObject; inline;
procedure SetObject(const AnObject: TObject); overload; inline;
function GetValue: T; inline;
procedure SetValue(const AValue: T); overload; inline;
procedure CheckGuard; inline;
end;
{ TAutoPtr
constructor TAutoPtr
begin
end;
destructor TAutoPtr
begin
inherited;
end;
{ TAutoPtr
procedure TAutoPtr
begin
end;
class procedure TAutoPtr
begin
end;
function TAutoPtr
begin
end;
function TAutoPtr
begin
end;
function TAutoPtr
begin
end;
class procedure TAutoPtr
begin
end;
procedure TAutoPtr
begin
end;
procedure TAutoPtr
begin
end;
procedure TAutoPtr
begin
end;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Note that since these are reference counted, you might want to call them shared_ptr https://en.wikipedia.org/wiki/Smart_pointer#shared_ptr_and_weak_ptr. If you enforce the single-instance behaviour, observe that in C++ they are now called uniqe_ptr: https://en.wikipedia.org/wiki/Smart_pointer#unique_ptr
ReplyDeleteIn Spring4D this rename has already taken place a while ago: https://bitbucket.org/sglienke/spring4d/commits/e252b81fd3788cf5b82588721f68d00c892deb87
en.wikipedia.org - Smart pointer - Wikipedia
T n T , thanks a lot for your help, finally managed to get the code to compile.
ReplyDeleteJeroen Wiert Pluimers , well noted.
ReplyDelete