Board index » delphi » putting some code in the gym.

putting some code in the gym.

I have lots of arrays gathering data at the same time, although they could
start at different moments in time - I have a big calculation which is
repeated many times:

if choice1=true then begin
  for I1 = 1 to 10 do begin
  take1[I1]:= actual1 +(complicated_calculation*I1);
end end

if choice2=true then begin
  for I2 = 1 to 10 do begin
  take2[I2]:=actual2+(complicated_calculation*I2);
end end

if choice3=true then begin
  for I3 = 1 to 10 do begin
  take3[I3]:=actual3+(complicated_calculation*I3);
end end

I am trying the following with no luck!

procedure Texample.calculate(I, actual: integer; take array [1..360] of
integer);
begin
for I = 1 to 10 do begin
take[I]:=actual+(complicated_calculation*I];
end end;

using the following to extract the data:

calculate(I1, actual1, take1[I]);

It is implementing the array that is causing me grief!, any ideas?

thanks

 

Re:putting some code in the gym.


Quote
Matt Laver wrote:
> I have lots of arrays gathering data at the same time, although they could
> start at different moments in time - I have a big calculation which is
> repeated many times:

> [code snipped]

> I am trying the following with no luck!

> procedure Texample.calculate(I, actual: integer; take array [1..360] of
> integer);
> begin
> for I = 1 to 10 do begin
> take[I]:=actual+(complicated_calculation*I];
> end end;

> using the following to extract the data:

> calculate(I1, actual1, take1[I]);

                         ^^^^^^^^^ here you ONE element of the array
but you declarde the procedure to expect an array (with 360 elements)
Aswell you're using a parameter instead of a local var (I)! Who the hell
taught you that?

Try this:

procedure NewCalc(const actual: integer; var arrTake: array of integer);
var
  i: integer;
begin
  for i:= Low(arrTake) to High(arrTake) do
    arrTake[i]:= actual + (comp_calc * i);
end;

Bye, Udo

Other Threads