<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">On 06/07/2025 16:17, Zoë Peterson via
fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:D9E72E52-DDBF-4D11-9514-166236521B6B@scootersoftware.com">
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">I would personally call that unusual at best
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
What do you two expect this construct to do that you think the current behavior is wrong? It’sobviously correct and expected to me as a fundamental part of Object Pascal’s polymorphism. Constructing an object from a class reference is the entire reason that constructors are virtual. It’s how things like TPicture.Graphic are implemented to create the correct image loading object.
</pre>
</blockquote>
<br>
In the below, calling<br>
fc.Create;<br>
is ok.<br>
<br>
fc is a variable, and its value is a class. (that can be TFoo, or
TFooChild)<br>
<br>
Calling<br>
TFooClass.Create <br>
on the otherhand...<br>
<br>
TFooClass is not a class. Its a type for a variable that then as
value can have a class.<br>
<br>
And, it also seems to Statically translate into <br>
TFooClass.Create == TFoo.Create.<br>
<br>
The type TFooClass itself can not be assigned a value. So it is
always the same.<br>
<br>
<br>
To answer your question: I expected it to be an error.<br>
But if for cautious reasons that is not going to be, then at least a
warning, nothing less<br>
<br>
<br>
<br>
program Project1;
<br>
{$mode objfpc}
<br>
type TFoo = class end;
<br>
TFooClass = class of TFoo;
<br>
var f: TFoo;
<br>
fc: TFooClass;
<br>
begin
<br>
fc := TFoo;
<br>
f := fc.Create;
<br>
f := TFooClass.Create; // works
<br>
end.
</body>
</html>