Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi Prism/Compiler    [ Add a report in this area ]  
Report #:  89161   Status: Open
Record properties initialized using := in call to constructor are not always set
Project:  Embarcadero Prism Build #:  4.0.25.791
Version:    1.1 Submitted By:   Robert Ogren
Report Type:  Basic functionality failure Date Reported:  10/22/2010 5:10:11 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   281208
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
I'm having problems using the extended constructor call syntax for initializing properties in records from assemblies not created in Delphi Prism.

If we pretend that System.Drawing.Point only has a constructor that takes 0 arguments, the following two ways of creating and initializing a Points should be equivalent, shouldn't they?

  var p1: System.Drawing.Point := new System.Drawing.Point;
  p1.X := 11;
  p1.Y := 22;
  Console.WriteLine(String.Format('Test system point X={0}, Y={1}', p1.X, p1.Y));

  var p2: System.Drawing.Point := new System.Drawing.Point(X := 33, Y := 44);
  Console.WriteLine(String.Format('Test system point X={0}, Y={1}', p2.X, p2.Y));

However, if you add the lines above to a console application and add a reference to System.Drawing.dll, the output is:

Test system point X=11, Y=22
Test system point X=0, Y=0

I.e. my property initializations are silently ignored by the compiler!

In my case I was actually trying to initialize an array of records that are from a legacy DLL and only have public fields, no constructors.

If you create the following record in Prism:

  MyPoint = public record
  public
    X: Integer;
    property Y: Integer;
  end;

This works:

  var p3: MyPoint := new MyPoint(X := 55, Y := 66);
  Console.WriteLine(String.Format('Test system point X={0}, Y={1}', p3.X, p3.Y));
Steps to Reproduce:
Compile and run the attached sample application
Workarounds
None
Attachment
89161.zip
Comments

None

Server Response from: ETNACODE01