Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.

Public Report
Report From: Delphi Prism/Compiler    [ Add a report in this area ]  
Report #:  98805   Status: Open
Changes to var record parameters are lost in some cases
Project:  Embarcadero Prism Build #:  5.0.29.893
Version:    2010.1 Submitted By:   Robert Ogren
Report Type:  Basic functionality failure Date Reported:  9/12/2011 2:23:40 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   287608
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
Consider the following program. In Embarcadero Prism XE2, Oxygene version 5.0.29.893, the changes to the field R.A in the method MyRecInc are not saved to the R parameter. If the value is first stored in a local variable as with the example with the R.B field, the new value is saved. The output of the program should be R.A=1, R.B=1, not "R.A=0, R.B=1".

type
  MyRec = record
    A: Integer;
    B: Integer;
  end;

  ConsoleApp = class
  public
    class method MyInc(var X: Integer);
    class method MyRecInc(var R: MyRec);
    class method Main(args: array of String);
  end;

implementation

class method ConsoleApp.MyInc(var X: Integer);
begin
  X := X + 1;
end;

class method ConsoleApp.MyRecInc(var R: MyRec);
var
  Z: Integer;
begin
  MyInc(var R.A);
  Z := R.B;
  MyInc(var Z);
  R.B := Z;
end;

class method ConsoleApp.Main(args: array of String);
var
  R: MyRec;
begin
  R.A := 0;
  R.B := 0;
  MyRecInc(var R);
  Console.WriteLine('Test 2');
  Console.WriteLine('Expected result: R.A=1, R.B=1');
  Console.WriteLine(String.Format('Actual result:   R.A={0}, R.B={1}', R.A, R.B));
  Console.ReadLine;
end;
Steps to Reproduce:
Paste the code from the issue description into a new console application, or use the attached sample project. Run the application and compare the actual and expected outputs that the program prints to the console.
Workarounds
None
Attachment
RecordVar.zip
Comments

None

Server Response from: ETNACODE01