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?

 
OK, several things:

Code indention - it has nothing to do with program execution BUT, it makes your code more readable. (to you)

Look at procedure TMainForm.xHold; (above) Let's ignore the error for a moment and look at code structure:
Look at each line. Do you see that the value of 'N' and the 2nd param to 'HoldCall()' are common? Therefore the entire xHold procedure could be re-written as:
Code:
procedure TMainForm.xHold;
begin
  SimpleSIP1.HoldCall(CallPack, N, 0);
end;
Please compare your 10 lines of code to my 1 line of code. Be sure you understand why (how) they do EXACTLY the same thing before continuing. (PLEASE)

Note: You're still going to get error "Incompatible types: 'Array' and 'ISipCall'". BUT, you'll get the error just once, not 10 times or places. Also note my use of indention. Note also that I surrounded my code with [[]code][[]/code] tags to make it stand out in this forum (has nothing to do with programming, but...) See:
Now for the error:

What 'TYPE' is defined for the 1st param in procedure HoldCall?
What 'TYPE' is CallPack? An array?
What 'TYPE' is ISipCall?
You have to KNOW these answers. You appear to be guessing with trial and error

Try building your program incrementally. In other words, get the first line of code working before going to the next. If you already have many lines of code, comment it out and start at the beginning. DO make a flow chart of your program so you can follow it as a map. Check things off as you complete them. Trust that if you can't develop a working flow diagram, your program won't work either. As things change, redraw the flow chart. Stick to it. Use functions where your flow chart has to make a yes/no decision, like this:
Code:
function connected: boolean;
begin
  result:= MyConnection.Active
end;
Use it in your code like this:
Code:
begin
  if Connected then
    CollectData
  else
    ShowMessage('not connected')
end;

Lastly, as you code, think of your program having two parts. Well three really, where the 3rd is the interface, the least important initially. "Who cares that it's pretty if it don't work?!?". The parts to concentrate on are input and output. For each function or procedure, ask yourself:
Do I have all I need to put this out?
Where am I going to get it from?
Will I need it again? (local variable or global)
Where am I going to store it?

Also visualize the data in your array by writing it down. An array is a matrix. A single dimensional array has just one row. Each element of that row is referenced by index, usually "i". Two dimensional arrays are usually referenced with indices "x" and "y" but the integer variable names could be anything.

The data TYPE of each element can be whatever you define it as. Dynamic arrays have their benefits but until you know how to work with static arrays both forward and backward, I'd avoid using dynamic arrays.

Roo
Delphi Rules!
 
I have nothing to add here, so * for you roo!

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
that code doesn't do the same thing as my 10 as there are 10 separate conditions of N.
I dont know what you mean by N and HoldCall() are COMMON.
What 'TYPE' is defined for the 1st param in procedure HoldCall? 'N' is Integer.
As for Indention I have to write code in a way that I can easily read (ME dyslexic! cross-lateral!).
What 'TYPE' is CallPack? An array? yes an array of ISipCall.
What 'TYPE' is ISipCall? this is the difficult part I am using code from a demo of a sip phone, If I hold down ctrl with my mouse over the word ISipCall I get a pop up message which says "Unable to locate file sipints.pas".
You are not the first person that has mentioned flow chart...I have a question/concern:

Do Flow charts require extra programming or do they update with changes to you code? I cannot understand what the point would be of having a chart that does nothing else than 'look pretty' ("Who cares that it's pretty if it don't work?!?") I can see the point In using a Flow chart if It properly represents the working function of my code (showing how I really have connected things, NOT how I think I have connected things) I may be wrong but flow charts look like they require extra separate programming (??? there is no guaranty that It would properly represent what is happening in my real code) Please explain.

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top