E2029 delphi: ')' expected, but ',' found

Viewed 253

Compiler say that's wrong, why?

procedure TForm1.Button2Click(Sender: TObject);
Var
   IniOrb, CurOrb : TOrbitData;
   Orb : TOrbitData;
   KepEl: TKepEl;
   Cart: TCartesian;
   Geo: TGeo;
   D, T : TdateTime;
   Epoch : TdateTime;
   Time :  real;
    x, y, xstep : real;
begin
  Dat := Frac( DateTimePicker1.Time );
  Tim := Trunc ( DateTimePicker2.Date );
   Epoch := D + T;
   IniOrb := InitOrbit( Epoch, 1000, 0, 0, 0, 0, 60 * cToRad );
   Time := 60;
   Repeat
      CurOrb := TOrbitData(Time, KepEl, Cart, Geo);
                                                 ^
                                                ')' expected but ',' found

That's a record:

type TOrbitData = record  // full orbit data
        Epoch : TDateTime;
        KepEl : TKepEl;
        Cart  : TCartesian;
        Geo   : TGeo;
  end;

Error on the semicolon: ')' expected, but ';' found. What's wrong?

1 Answers

You cannot construct an instance of a record the way you are trying to.

But, you can add a constructor to your record type, eg:

type
  TOrbitData = record  // full orbit data
    Epoch : TDateTime;
    KepEl : TKepEl;
    Cart  : TCartesian;
    Geo   : TGeo;

    constructor Create(AEpoch: TDateTime; AKepEl: TKepEl; ACart: TCartesian; AGeo: TGeo);
  end;

constructor TOrbitData.Create(AEpoch: TDateTime; AKepEl: TKepEl; ACart: TCartesian; AGeo: TGeo);
begin
  Epoch := AEpoch;
  KepEl := AKepEl;
  Cart := ACart;
  Geo := AGeo;
end;

And then you can use it like this:

CurOrb := TOrbitData.Create(Time, KepEl, Cart, Geo);

Otherwise, you will have to define a standalone function to return an initialized instance of your record, like you did with InitOrbit().

Related