Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array (tiny problem) 1

Status
Not open for further replies.

Bamben

Programmer
Jul 22, 2009
70
IT
I have 2 arrays...

apple : fruit;
Pack:array[1..5] of fruit;
BOX:array[1..10] of fruit;

I have finished all the code for a small program dealing with these arrays, but...I get an error saying Undeclared Identifier 'i' (note that the error is only coming up for the 'i' used on the array 'PACK')

SomeComponent.EatFruit(Pack);//problem!!
SomeComponent.EatFruit(BOX);


By using Im trying to refer to the whole array.(I do this with both and that's the problem)

I successfully did it yesterday but only with one array.


I Can refer to parts of the arrays like this:

SomeComponent.EatFruit(Pack[1]);

but I cant use as a method for refering to the whole part of an array 'twice' on 2 different arrays...

I really don't know what I can do about it...Please how do I do this?

 
This may be a silly question, but are you declaring i ?

(if its in a procedure or function it should be local)

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
I don't recall having to do that yesterday, plus I have some code from a friend (where he uses an array) and I cant see where he has declared i.

that would mean I have two i's to declare...wouldn't it?

how do you declare i? I thought it was a built in function of the array.

how come it only gives me error for one one of the arrays and not the other? I swear I hav'nt declared it!!!

so nope that question was not silly. :p

 
ok thanks by the way i figured out how to declare i lol it was easy!!! lololol
 
If you want to refer to the entire array, would you not just use:

SomeComponent.EatFruit(Pack);
SomeComponent.EatFruit(BOX);

If you use:

SomeComponent.EatFruit(Pack);
SomeComponent.EatFruit(BOX);

you are just referencing the i element of Pack and BOX.
 
interesting...I never thought of that
 
seing that array box and pack are different sizes you would never use i together so

var a,b: integer;
begin
...
SomeComponent.EatFruit(Pack[a]);
SomeComponent.EatFruit(BOX);
end

Aaron
 
@bambin - you are so eager to learn and so thrilled when you figure something out that you are doing yourself a great injustice if you have not opened the tutorial link I have provided for you. The lessons will put you miles ahead of your next trial and error session, I promise you...

Roo
Delphi Rules!
 
Thanks roo0047 but Its too basic! I have read it my first day of learning.
 
I've now got an application that works up to a point but it still crashes with ACCESS VIOLATION when it gets to the line that uses 'i'. I think it crashes because I havn't managed to fill up my array CallPack[1..10] with 10 things.

My program gradually assigns live phone calls to the array but some times the phone calls get dropped. The problem I am having with my present knowledge is that I only get one chance to add a call to the arry CallPack[1]:= addcall;

Is there a way to assign some thing to an array filling up the next available space?

Because right now my code is HHHHHHHUGE! I have repeated the same code ten times for each CallPack[1],CallPack[2],CallPack[3],ect...
 
Thanks roo0047 but Its too basic! I have read it my first day of learning.
You're kidding Right?!? The link was page ONE of eight chapters. At the end there are links leading to thousands of utilities, tips and functions that I still use after 20 years of coding.
..my code is HHHHHHHUGE! I have repeated the same code ten times...
No wonder!


And here we are in a thread where you don't understand how an array index works. So, how much of this do you know?

You will really find this far more useful than asking one question at a time in a forum.

HTH (hope that helps) I really am trying to help you.

Roo
Delphi Rules!
 
From a source code maintainability standpoint, I would avoid the use of the word "Pack" as a variable name, especially for an array. "Packed" is a keyword, which will inevitably cause confusion.
 
I have never seen this page before (thanks roo!) the net has never been one of my strong points.
 
Hey! one sec, I have been here! Not to this contents page but I have read over and over all the articles about arrays on this site (as the related links to array articles) and no where does it describe how to control a whole array at once...

I have all day, 7 days a week free as I have no money and I am away from friends in a different country in fact, so I have zero distraction, I am spending allll of my time on this (btw: my code is no longer Huuuuuge! I have improved) I am trying very hard to understand what I read and I feel like I have ploughed through and exhausted Google to find all I can use to make sense of arrays (In fact I am now not entirely sure that the array is my real problem.
I DO believe I understand arrays, but my reason for not being able to get this one to respond 'I think', lies not in my inability to control a simple array but in the command that I put to the whole array after (the application is unable to complete for every element in the array as even some of the elements don't have calls assigned to them) SimpleSIP1.HoldCall(CallPack);

I basicly am telling the whole array (CallPack:array[0..9] of ISipCall;) to HoldCall. This would only work if all ten calls were active, but I am trying to hold the array when it is not full (after each phone call is added).

example: I have 2 active calls, before I go to call 3 I hold, un-hold, and hold the array(so that no calls will drop as they drop if they are on hold too long).

also I can't control the whole call pack like this:

SomeComponent.EatFruit(Pack);(Quote 'Jackmason')

when I try it looks like this:

SimpleSIP1.HoldCall(CallPack);

because I get the error: Incompatible types: 'Array' and 'ISipCall'

This is not a simple array of integers!

I have been trying really hard with no success to assign parts of the array to 'i', ie: if the next call becomes active I would try to say things like:

i := 0 to 1 do

but this doesn't work as...???? I get tones of errors, even though I have seen code like this used here:
the only answer I can think of right now is that there must be a way of rather than specifying the number of elements in the array from the beginning, as they are all inactive at first (with no assigned 'active' call), I don't think it would be entirely unreasonable to assume that there could be a way of adding elements to the array rather than assigning calls to the elements (growing the array as it were).

does this make sense?

I feel like I am going slowly mad...
 
Dynamic Array...set length....(re-thankyou roo, note: I was not un-thanking you in my last post but, I do believe that my array is not the problem) 'If you get me' its just kind of driving me nuts. but anyway I have more reading to do now unless I am wrong in my reasoning (please correct)

I am LEARNDING!!! :p
 
SetLength(CallPack, Length(CallPack)+1);

for T := Low(CallPack) to High(CallPack) do
CallPack[T] := SimpleSIP1.HoldCall(CallPack[T]);

I am doing it wrong wrong wrong, I am getting really confused with where I call put these lines as they want to be in a local procedure, but then when I put them in a local procedure the SimpleSIP1 ISipCall is not recognised?

Incompatible types: procedure, untyped pointer or untyped parameter' and ISipCall
 
I am really lost, reading isn't helping (I am trying lots of things from pages on the net but it isn't going well)

I am trying now to control parts of the array as the calls become active. Every time I place a call and check that it is active then inc 'N' before holding:

procedure TMainForm.xUnHold(i:integer);
begin
if N = 1 then SimpleSIP1.HoldCall(CallPack[0]);
if N = 2 then begin for T = 0 to 1 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 3 then begin for T = 0 to 2 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 4 then begin for T = 0 to 3 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 5 then begin for T = 0 to 4 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 6 then begin for T = 0 to 5 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 7 then begin for T = 0 to 6 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 8 then begin for T = 0 to 7 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 9 then begin for T = 0 to 8 do SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 10 then begin for T = 0 to 9 do SimpleSIP1.HoldCall(CallPack[T]);end;
end;

(I am improperly using 'for to do' which is a loop)

I need to find some way of assigning more than one number to 'T'
......................................................
This doesn't work ether (tones of errors!!!)

procedure TMainForm.xHold(T:integer);
begin
if N = 1 then SimpleSIP1.HoldCall(CallPack[0]);
if N = 2 then begin T := (CallPack, 2, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 3 then begin T := (CallPack, 3, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 4 then begin T := (CallPack, 4, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 5 then begin T := (CallPack, 5, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 6 then begin T := (CallPack, 6, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 7 then begin T := (CallPack, 7, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 8 then begin T := (CallPack, 8, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 9 then begin T := (CallPack, 9, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 10 then begin T := (CallPack, 10, 0); SimpleSIP1.HoldCall(CallPack[T]);end;
end;
 
No...try again!

procedure TMainForm.xHold;
begin
if N = 1 then begin T := 0; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 2 then begin T := 0, 1; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 3 then begin T := 0, 1, 2; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 4 then begin T := 0, 1, 2, 3; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 5 then begin T := 0, 1, 2, 3, 4; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 6 then begin T := 0, 1, 2, 3, 4, 5; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 7 then begin T := 0, 1, 2, 3, 4, 5, 6; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 8 then begin T := 0, 1, 2, 3, 4, 5, 6, 7; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 9 then begin T := 0, 1, 2, 3, 4, 5, 6, 7, 8; SimpleSIP1.HoldCall(CallPack[T]);end;
if N = 10 then begin T := 0, 1, 2, 3, 4, 5, 6, 7, 8, 9; SimpleSIP1.HoldCall(CallPack[T]);end;
end;
 
procedure TMainForm.xHold;
begin
if N = 1 then SimpleSIP1.HoldCall(CallPack, 1, 0);
if N = 2 then SimpleSIP1.HoldCall(CallPack, 2, 0);
if N = 3 then SimpleSIP1.HoldCall(CallPack, 3, 0);
if N = 4 then SimpleSIP1.HoldCall(CallPack, 4, 0);
if N = 5 then SimpleSIP1.HoldCall(CallPack, 5, 0);
if N = 6 then SimpleSIP1.HoldCall(CallPack, 6, 0);
if N = 7 then SimpleSIP1.HoldCall(CallPack, 7, 0);
if N = 8 then SimpleSIP1.HoldCall(CallPack, 8, 0);
if N = 9 then SimpleSIP1.HoldCall(CallPack, 9, 0);
if N = 10 then SimpleSIP1.HoldCall(CallPack, 10, 0);
end;

Incompatible types: 'Array' and 'ISipCall'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top