Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
3rdRail
Blackfish SQL
C#Builder
C++BuilderX
CodeCentral
Conference
DBArtisan
Delphi for PHP
Delphi Prism
Delphi-BCB
EDN
InterBase
JBuilder
JBuilder 2007
Kylix
Optimizeit
QualityCentral
Test project
You are not logged in.
Help
Print
Public Report
Report From:
[ Add a report in this area ]
Report #:
8521
Status:
Reported
Cannot call constructors using instance variables
Project:
Build #:
7.1.1523.17956
Version:
8.0
Submitted By:
Peter Gummer
Report Type:
Basic functionality failure
Date Reported:
6/28/2004 8:00:54 PM
Severity:
Infrequently encountered problem
Last Updated:
Platform:
All platforms
Internal Tracking #:
Resolution:
None
Resolved in Build:
:
None
Duplicate of:
None
Voting and Rating
Overall Rating:
(1 Total Rating)
5.00 out of 5
Total Votes:
10
Description
In Delphi 1 to 7, this was legal:
TObject.Create.Create;
In Delphi 8, the compiler complains, "Cannot call constructors using instance variables". Yet according to the on-line help it should still be legal:
ms-help://borland.bds2/bds2guide/html/Methods.htm:
"When a constructor is called using an object reference (rather than a class reference), it does not create an object. Instead, the constructor operates on the specified object, executing only the statements in the constructor's implementation, and then returns a reference to the object."
In Delphi 1 to 7, calling o.Create (where o is an object reference) reinitialised the same object o.
What seems to have changed in Delphi 8 is that:
1. Calls of the form o.Create (where o is an object reference) are now illegal.
2. Calls of the form Self.Create (where Self is an object reference) now create a new object of the same type as the old one.
Maybe the behaviour was deliberately changed in Delphi 8, but given that there is no documentation to this effect I can only assume that this is a bug in the compiler.
Steps to Reproduce:
This code demonstrates the behaviour in Delphi 8. All previous versions of Delphi behave completely differently.
type
T1 = class
public
function Clone: T1;
end;
function T1.Clone: T1;
begin
Result := Create;
end;
function Test: string;
var
o1, o2: T1;
begin
o1 := T1.Create;
o2 := o1.Clone;
Result := o2.ClassType.ClassName;
if o1 <> o2 then Result := Result + ' - different instances';
// At this point, Result = 'T1 - different instances'
end;
Workarounds
None
Attachment
None
Comments
None
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us