2
votes

I'm trying to compile the following code in Delphi Rio:

unit untObjectHelper;

interface

uses
   SysUtils;

type
   TObjectHelper = class(TInterfacedObject)
   public
      class procedure Clone(const objOrigem: TObject; const objDestino: TObject);
   end;

implementation

uses
   System.Rtti;

{ TObjectHelper }

class procedure TObjectHelper.Clone(const objOrigem,
   objDestino: TObject);
begin
   if not Assigned(objOrigem) then
      Exit;

   if not Assigned(objDestino) then
      Exit;

   if objOrigem.ClassType <> objDestino.ClassType then
      Exit;

   var contexto := TRttiContext.Create;
   try
      var tipo := contexto.GetType(objOrigem.ClassType);
      var campos := tipo.GetFields();
   finally
      contexto.Free;
   end;
end;

end.

however the following error occurs:

[dcc32 Fatal Error] untObjectHelper.pas (36): F2084 Internal Error: NC1921

on the line:

var fields: = type.GetFields ();

version: Embarcadero® Delphi 10.3 Version 26.0.33219.4899

I did not find reference to this error, could someone help me? thank you very much

1
Looks like something you should be reporting to QC. Not surprised with the introduction of in-line variables. Try pre-declaring that variable, or both. Probably a combination of that + RTTI.Jerry Dodge
I don't have Rio, but in Seattle, you can't declare a variable named "Type". So, I'd try to rename the variable something else, or use "&Type".Ken Bourassa
@LURD, i fixed the code, was the translatorPassella
@JerryDodge you are correct, declaring in the variable section, the code compiledPassella
@KenBourassa, i fixed the codePassella

1 Answers

2
votes

The problem is the type inference, thanks to Rudy Velthuis for the tip

unit untObjectHelper;

interface

uses
   SysUtils;

type
   TObjectHelper = class(TInterfacedObject)
   public
      class procedure Clone(const objOrigem: TObject; const objDestino: TObject);
   end;

implementation

uses
   System.Rtti;

{ TObjectHelper }

class procedure TObjectHelper.Clone(const objOrigem,
   objDestino: TObject);
begin
   if not Assigned(objOrigem) then
      Exit;

   if not Assigned(objDestino) then
      Exit;

   if objOrigem.ClassType <> objDestino.ClassType then
      Exit;

   var contexto := TRttiContext.Create;
   try
      var tipo := contexto.GetType(objOrigem.ClassType);
      var campos: TArray<TRttiField> := tipo.GetFields();
   finally
      contexto.Free;
   end;
end;

end.