Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Is it possible to move a dynamic array to a static array?

LecutusLecutus Member Posts: 5
Is it possible to move a dynamic array to a static array?
The statics are listed below
Type
ReStart = Record
CurrentFoot : integer; // should be an array,
TtlStrx : Real; // should be an array
T0 : real ;
GC0 : real;
GC1 : real;
GC2 : real;
LagFoot : Array[1..250] of Integer;
LagStrx : Array[1..250] of Integer;
ROPFt : Array[1..250] of Integer;
ROPTm : Array[1..250] of Real;
GasFt : Array[1..250] of Integer;
GasAmt : Array[1..250] of Real;
end;


The dynamics are defined as:
ROPFtDraw, GasFtDraw : array of integer;
ROPTmDraw, GasAmtDraw, GasAveArray : array of Real;


The dynamics are usually less than a hundred places in length.

Here's how I'm trying:
For ei := 0 to Length(GasFtDraw)-1 do
Begin
EmergencyRec.GasFt[ei] := GasFtDraw[ei];
EmergencyRec.GasAmt[ei] := GasAmtDraw[ei] ;
End;

gx := 0;

Repeat
EmergencyRec.GasFt[gx] := GasFtDraw[gx];
EmergencyRec.GasAmt[gx] := GasAmtDraw[gx] ;
inc(gx);
until gx >= (Length(GasFtDraw)-1);


Both versions give an error: Range check error

Is it possible to do dynamic to static?

Comments

  • zibadianzibadian Member Posts: 6,349
    : Is it possible to move a dynamic array to a static array?
    : The statics are listed below
    : Type
    : ReStart = Record
    : CurrentFoot : integer; // should be an array,
    : TtlStrx : Real; // should be an array
    : T0 : real ;
    : GC0 : real;
    : GC1 : real;
    : GC2 : real;
    : LagFoot : Array[1..250] of Integer;
    : LagStrx : Array[1..250] of Integer;
    : ROPFt : Array[1..250] of Integer;
    : ROPTm : Array[1..250] of Real;
    : GasFt : Array[1..250] of Integer;
    : GasAmt : Array[1..250] of Real;
    : end;
    :
    :
    : The dynamics are defined as:
    : ROPFtDraw, GasFtDraw : array of integer;
    : ROPTmDraw, GasAmtDraw, GasAveArray : array of Real;
    :
    :
    : The dynamics are usually less than a hundred places in length.
    :
    : Here's how I'm trying:
    : For ei := 0 to Length(GasFtDraw)-1 do
    : Begin
    : EmergencyRec.GasFt[ei] := GasFtDraw[ei];
    : EmergencyRec.GasAmt[ei] := GasAmtDraw[ei] ;
    : End;
    :
    : gx := 0;
    :
    : Repeat
    : EmergencyRec.GasFt[gx] := GasFtDraw[gx];
    : EmergencyRec.GasAmt[gx] := GasAmtDraw[gx] ;
    : inc(gx);
    : until gx >= (Length(GasFtDraw)-1);
    :
    :
    : Both versions give an error: Range check error
    :
    : Is it possible to do dynamic to static?
    :
    :
    You code will work, once you set the length of the dynamic array using SetLength(). The error come from the fact that dynamic arrays are pointers to an array. At the start of the program these arrays have 0 elements, and are thus unusable.
  • LecutusLecutus Member Posts: 5
    : : Is it possible to move a dynamic array to a static array?
    : : The statics are listed below
    : : Type
    : : ReStart = Record
    : : CurrentFoot : integer; // should be an array,
    : : TtlStrx : Real; // should be an array
    : : T0 : real ;
    : : GC0 : real;
    : : GC1 : real;
    : : GC2 : real;
    : : LagFoot : Array[1..250] of Integer;
    : : LagStrx : Array[1..250] of Integer;
    : : ROPFt : Array[1..250] of Integer;
    : : ROPTm : Array[1..250] of Real;
    : : GasFt : Array[1..250] of Integer;
    : : GasAmt : Array[1..250] of Real;
    : : end;
    : :
    : :
    : : The dynamics are defined as:
    : : ROPFtDraw, GasFtDraw : array of integer;
    : : ROPTmDraw, GasAmtDraw, GasAveArray : array of Real;
    : :
    : :
    : : The dynamics are usually less than a hundred places in length.
    : :
    : : Here's how I'm trying:
    : : For ei := 0 to Length(GasFtDraw)-1 do
    : : Begin
    : : EmergencyRec.GasFt[ei] := GasFtDraw[ei];
    : : EmergencyRec.GasAmt[ei] := GasAmtDraw[ei] ;
    : : End;
    : :
    : : gx := 0;
    : :
    : : Repeat
    : : EmergencyRec.GasFt[gx] := GasFtDraw[gx];
    : : EmergencyRec.GasAmt[gx] := GasAmtDraw[gx] ;
    : : inc(gx);
    : : until gx >= (Length(GasFtDraw)-1);
    : :
    : :
    : : Both versions give an error: Range check error
    : :
    : : Is it possible to do dynamic to static?
    : :
    : :
    : You code will work, once you set the length of the dynamic array using SetLength(). The error come from the fact that dynamic arrays are pointers to an array. At the start of the program these arrays have 0 elements, and are thus unusable.
    :

  • LecutusLecutus Member Posts: 5
    : : : Is it possible to move a dynamic array to a static array?
    : : : The statics are listed below
    : : : Type
    : : : ReStart = Record
    : : : CurrentFoot : integer; // should be an array,
    : : : TtlStrx : Real; // should be an array
    : : : T0 : real ;
    : : : GC0 : real;
    : : : GC1 : real;
    : : : GC2 : real;
    : : : LagFoot : Array[1..250] of Integer;
    : : : LagStrx : Array[1..250] of Integer;
    : : : ROPFt : Array[1..250] of Integer;
    : : : ROPTm : Array[1..250] of Real;
    : : : GasFt : Array[1..250] of Integer;
    : : : GasAmt : Array[1..250] of Real;
    : : : end;
    : : :
    : : :
    : : : The dynamics are defined as:
    : : : ROPFtDraw, GasFtDraw : array of integer;
    : : : ROPTmDraw, GasAmtDraw, GasAveArray : array of Real;
    : : :
    : : :
    : : : The dynamics are usually less than a hundred places in length.
    : : :
    : : : Here's how I'm trying:
    : : : For ei := 0 to Length(GasFtDraw)-1 do
    : : : Begin
    : : : EmergencyRec.GasFt[ei] := GasFtDraw[ei];
    : : : EmergencyRec.GasAmt[ei] := GasAmtDraw[ei] ;
    : : : End;
    : : :
    : : : gx := 0;
    : : :
    : : : Repeat
    : : : EmergencyRec.GasFt[gx] := GasFtDraw[gx];
    : : : EmergencyRec.GasAmt[gx] := GasAmtDraw[gx] ;
    : : : inc(gx);
    : : : until gx >= (Length(GasFtDraw)-1);
    : : :
    : : :
    : : : Both versions give an error: Range check error
    : : :
    : : : Is it possible to do dynamic to static?
    : : :
    : : :
    : : You code will work, once you set the length of the dynamic array using SetLength(). The error come from the fact that dynamic arrays are pointers to an array. At the start of the program these arrays have 0 elements, and are thus unusable.
    : :
    :
    :
    I do use the SetLength during the course of the program. The size of the dynamic varies to no more than 150 elements. This section I'm talking about is for emergency backup situation. So at any moment I'll need to move the dynamic array, of any size, to the staitc array. So the dynamic array, GasFtDraw, is usable.
    L.
  • zibadianzibadian Member Posts: 6,349
    : : : : Is it possible to move a dynamic array to a static array?
    : : : : The statics are listed below
    : : : : Type
    : : : : ReStart = Record
    : : : : CurrentFoot : integer; // should be an array,
    : : : : TtlStrx : Real; // should be an array
    : : : : T0 : real ;
    : : : : GC0 : real;
    : : : : GC1 : real;
    : : : : GC2 : real;
    : : : : LagFoot : Array[1..250] of Integer;
    : : : : LagStrx : Array[1..250] of Integer;
    : : : : ROPFt : Array[1..250] of Integer;
    : : : : ROPTm : Array[1..250] of Real;
    : : : : GasFt : Array[1..250] of Integer;
    : : : : GasAmt : Array[1..250] of Real;
    : : : : end;
    : : : :
    : : : :
    : : : : The dynamics are defined as:
    : : : : ROPFtDraw, GasFtDraw : array of integer;
    : : : : ROPTmDraw, GasAmtDraw, GasAveArray : array of Real;
    : : : :
    : : : :
    : : : : The dynamics are usually less than a hundred places in length.
    : : : :
    : : : : Here's how I'm trying:
    : : : : For ei := 0 to Length(GasFtDraw)-1 do
    : : : : Begin
    : : : : EmergencyRec.GasFt[ei] := GasFtDraw[ei];
    : : : : EmergencyRec.GasAmt[ei] := GasAmtDraw[ei] ;
    : : : : End;
    : : : :
    : : : : gx := 0;
    : : : :
    : : : : Repeat
    : : : : EmergencyRec.GasFt[gx] := GasFtDraw[gx];
    : : : : EmergencyRec.GasAmt[gx] := GasAmtDraw[gx] ;
    : : : : inc(gx);
    : : : : until gx >= (Length(GasFtDraw)-1);
    : : : :
    : : : :
    : : : : Both versions give an error: Range check error
    : : : :
    : : : : Is it possible to do dynamic to static?
    : : : :
    : : : :
    : : : You code will work, once you set the length of the dynamic array using SetLength(). The error come from the fact that dynamic arrays are pointers to an array. At the start of the program these arrays have 0 elements, and are thus unusable.
    : : :
    : :
    : :
    : I do use the SetLength during the course of the program. The size of the dynamic varies to no more than 150 elements. This section I'm talking about is for emergency backup situation. So at any moment I'll need to move the dynamic array, of any size, to the staitc array. So the dynamic array, GasFtDraw, is usable.
    : L.
    :
    I see the problem. The static array is a 1-indexed array, while the dynamic arrays are 0-indexed. You should change your static array to array[0..249] or add 1 to the ei for the static arrays only.
Sign In or Register to comment.