Talk:E2382 Cannot call constructors using instance variables (Delphi)

From RAD Studio
Jump to: navigation, search

"No further information is available for this error or warning."

What does it mean? What I need to do when I had this error message??? Aspecially when trying recompile sources, that was compiled in earler versions of Delphi? --Nashev (talk) 05:34, 9 October 2013 (PDT)

Response

You should not be receiving E2382 anymore. Have you received this error message? Were you trying to recompile source that was compiled in an earlier version of Delphi? Can you give any additional information?

Let us know - we can investigate and document this error if it has been emitted by RAD Studio.

KrisHouser (talk) 16:24, 9 October 2013 (PDT)

Case and solution

I had function Clone in this form:

function TMyClass.Clone: TMyClass;
begin
  Result := Create(FField);
end;

where Create is a my constructor which have initialization of FField in constructed instance by argument.

This call produce this error in Delphi XE5

Solution is to call constructor with class name:

function TMyClass.Clone: TMyClass;
begin
  Result := TMyClass.Create(FField);
end;

this function compiles properly. Does it mean that in first case constructor are called for calling instance, for Self, not only from constructors? --Nashev (talk) 23:27, 9 October 2013 (PDT)