| | |
Delphi re-indexes arrays passed to functions?
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 9
Reputation:
Solved Threads: 0
Hi all,
I don't use Delphi often so this is probably a stupid question again, but why does Delphi (7) re-index arrays when they're passed to a function, as a simplified example...
Why does it do this? Thanks in advance for any answers.
I don't use Delphi often so this is probably a stupid question again, but why does Delphi (7) re-index arrays when they're passed to a function, as a simplified example...
Pascal and Delphi Syntax (Toggle Plain Text)
program example; {$APPTYPE CONSOLE} uses SysUtils; var numbers: array[1..5] of Integer = (10, 20, 30, 40, 50); procedure example(var nums: array of Integer); begin WriteLn(nums[5]); //Undefined. 50 -> nums[4] end; begin Writeln(numbers[5]); example(numbers); Readln; end.
Why does it do this? Thanks in advance for any answers.
Last edited by TomRandall; Sep 27th, 2009 at 2:59 pm.
What if the added parameter type is not meet properly?
Listen,if you create a new type as array and pass it to the proc...
Listen,if you create a new type as array and pass it to the proc...
delphi Syntax (Toggle Plain Text)
program array1___; {$APPTYPE CONSOLE} uses SysUtils; type TArray = array[1..5]of integer; const numbers:TArray = (10,20,30,40,50); procedure example(const nums: TArray); begin WriteLn(nums[5]); end; begin Writeln(numbers[5]);{result is 50} example(numbers);{here too} Readln; end.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
![]() |
Similar Threads
- Having a problem with 'compatable types in assignment (C++)
- HELP..!! (C)
- sorting 2 arrays (C++)
- Question about Random Number Generators (C++)
- Functions - arrays/pointers re - const (C++)
- Hey Just started new topic with arrays, and having some trouble please help (C++)
- Can arrays be sent to functions in C? (C)
- Help with arrays (C++)
- returning arrays from functions (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: TCP server with md5 Authentication + 3des crypt
- Next Thread: How can I list the sorted results on the screen?
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi





