Ah yes. Good point.
Ah yes. Good point.
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
Thanks this way it works fine. I've never used pointers because I do not exactly understand them. What is the difference between a pointer and the variable itself except for the pointer uses less memory?
Yes, pointers are one of the harder things about programming. I'll have some links for you:
http://delphi.about.com/od/objectpas...a/pointers.htm
http://www.delphibasics.co.uk/Article.asp?Name=Pointers
Ok, I'll breifly explain them:
All your variables are stored in RAM memory. Pointers are also stored there, but they point to another location in RAM. They don't contain value's like 6 or "abc", but memory adresses.
A quick example:
Hope that helps.Code://Make a new pointer type that points to integers (not sure if this allready exists) type pinteger = ^integer; var v, w: integer; p: pinteger; begin v := 100; w := 50; p := @v; //the value of p is now the memory location of v showmessage( IntToStr( p^ ) ); //Output: 100 (^ means: show us what is stored at this memory location) v := v + 10; showmessage( IntToStr( p^ ) ); //Output: 110 p := @w; //Let p point to w now showmessage( IntToStr( p^ ) ); //output 40 p := nil; //NIL means "points to nothing" showmessage( IntToStr( p^ ) ); //gives an error end;
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
Okay I think I'm getting it. So basicly a pointer is what its name is: a pointer. And I could replace it with a variable however in your example an integer "p" variable would use more memory than the pointer "p" which doesn't store the true value of the other variables just their memory address. So maybe in this example it doesn't count much but if I wrote a bigger unit then it would be advisable for the defined types of the unit to make pointers for them and in the main program use those instead right?
My advice to you in terms or trying to access data outside of arrays is too have the array as a record or type, and a constant which tells you how long that array is. Then when you use loops to process data in that array, add a clause that breaks the loop when whatever position in the array you are processing is >= maximum length. That way you never get any crashes from processing data outside an array... It helps in debugging, especially if you have a lot of arrays, you can just rule that out in most cases. (unless you a clutz like me that defines an array 1..100 and then sets the limit to 250.... it took a while to find, trust me.)
hope this was useful,
code_glitch.
I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.
I know mistakes like that very well. The stupidest ones are always the hardest to find. And the advice was very useful thanks for it too.
Bookmarks