Forum > Beginners
Using arrays in routines, etc.
marcov:
--- Quote from: KodeZwerg on February 22, 2024, 12:10:29 pm ---
--- Quote from: Fibonacci on February 22, 2024, 10:47:50 am ---There isnt.
--- End quote ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure foo(bar: array of whatever);
--- End quote ---
That's a different construct, an open array. Not a dynamic array.
KodeZwerg:
--- Quote from: Fibonacci on February 22, 2024, 12:11:26 pm ---
--- Quote from: KodeZwerg on February 22, 2024, 12:10:29 pm ---
--- Quote from: Fibonacci on February 22, 2024, 10:47:50 am ---There isnt.
--- End quote ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure foo(bar: array of whatever);
--- End quote ---
As a result?
--- End quote ---
Feel free to add "out" infront to know that it's meant to be some kind of result, I usualy do "function x([var/out] y: array of z): boolean" to have a better workflow.
Topic titles "routines" and method "procedure" is one kind of a routine.
--- Quote from: marcov on February 22, 2024, 12:16:51 pm ---That's a different construct, an open array. Not a dynamic array.
--- End quote ---
Hmmm it accept static or dynamic, whats your point?
Fibonacci:
Damn you @KodeZwerg... I wanted to show you something, but I found another INTERNAL ERROR :o :o
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program test; function func(out values: array of string): boolean;begin values := ['hi']; // project1.lpr(5,10) Error: Assignments to formal parameters and open arrays are not possible // project1.lpr(5,13) Error: Internal error 99080501end; beginend.
Its my 4th today!
CM630:
--- Quote from: marcov on February 22, 2024, 10:48:47 am ---Use types.stringdynarray
Most dynamic arrays of basic types are predefined there.
--- End quote ---
I do not like TStringDynArray = array of AnsiString;
And there is no array of array of string; type there.
But there occurred to be a TStringArray in sysutils.
cdbc:
Hi
Sorry, for the intrusion, but I think it pertains to the thread-title...
I'm a bit uncertain about dynamic arrays as a function result.
If i have this function:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function fubar: TStringArray;begin SetLength(Result,5); Result[0]:= 'F*cked'; Result[1]:= 'Up'; Result[2]:= 'Beyond'; Result[3]:= 'All'; Result[4]:= 'Recognition';end; then
1) can i use it like: "S:= fubar()[2];" to get 'Beyond', or do I have to assign
the result to an array variable first?
2) Is the memory allocated to the array managed? or do I have to free it
somehow?
Btw. TStringArray is defined in sysutils... And as @marcov said most are predefined.
edit: What's stopping you from defining a 'TStringMatrix', e.g.:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TStringMatrix = array of TStringArray;Regards Benny
Navigation
[0] Message Index
[#] Next page
[*] Previous page