Hi,
TInfo=record
s: string;
i: integer;
end;
function func1(a: array of TInfo);how can i pass the parameter to that function?
for example, i cant do that?
func1([('test1', 1), ('test2', 2)]);
Mailing lists / fpc-pascal / 2012-02
20 messages · 8 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
TInfo=record
s: string;
i: integer;
end;
function func1(a: array of TInfo);how can i pass the parameter to that function?
for example, i cant do that?
func1([('test1', 1), ('test2', 2)]);That`s a question of mine too.
TInfo=record s: string; i: integer; end; function func1(a: array of TInfo); how can i…
Define a pointer type for TInfo then pass the pointer to the function. Dereference the pointer within the function to access the array.
Thomas Young
330-256-7064
www.tygraphics.net
Sent from my iPhone
Could you give an example? If not bother much.
That`s a question of mine too.
This is how I would do that. There may be a better way.
ATInfo = array[1..100] of TInfo;
ATInfoPtr = ^ATInfo;
Var
A:ATInfoPtr;function func1(a:ATInfoPtr);
Thomas Young
330-256-7064
www.tygraphics.net
Sent from my iPhone
Thanks.
This is how I would do that. There may be a better way. ATInfo = array[1..100] of TInfo;…
New(A);> function func1(a:ATInfoPtr);
var
Name:string;
N:integer;
begin
N:= 1;
Name:= a^[n].s;
end;Thomas Young
330-256-7064
www.tygraphics.net
Sent from my iPhone
This is how I would do that. There may be a better way. ATInfo = array[1..100] of TInfo;…
Thanks, but that is not my expected answer, my ask about "dynamic array of record" and without define a variable to pass it by params, for example i can pass the params for array of string like this
func2(['t1', 't1']); this work, but i want to extend the params info?
Best Regards
Zaher Dirkey
Thanks.
But they couldn't pass like this?:
Simply passing the array var if he had declared.
I guess the question of our friend was about to how to pass an array with record without the need to declare.
TInfo=record s: string; i: integer; end; function func1(a: array of TInfo); how can i…
You have to declare the parameter type independently of the function declaration. You can also do it without declaring an additional pointer type (which is also one way to do it), since dynamic arrays already have an implicit pointer. Something like this:
type
TInfo=record
s: string;
i: integer;
end;
TInfoArr = array of tInfo;
procedure proc1(a: TInfoArr);
implementation
procedure TForm1.Button1Click(Sender: TObject);
var rec: TInfo;
infoArr: TInfoArr = nil;
begin
SetLength(infoArr, 2);
rec.i := 1; rec.s := 'test1';
infoArr[0] := rec;
rec.i := 2; rec.s := 'test2';
infoArr[1] := rec;
proc1(infoArr);
end;
procedure proc1(a: TInfoArr);
var s: string = '';
i: integer;
begin
for i := Low(a) to High(a) do
s := s + Format('TInfo%d: s=%s, i=%d ',[i, a[i].s, a[i].i]);
Showmessage(s);
end;Thanks, but that is not my expected answer, my ask about "dynamic array of record" and…
Declaring record constants inline in the code is not supported by FPC (regardless of whether it's for an array parameter, an assignment or something else). There are no plans to add support for it either.
Jonas
Thanks, but that is not my expected answer, my ask about "dynamic array of record" and…
Thanks, but that is not my expected answer, my ask about "dynamic array of record" and without define a variable to pass it by params, for example i can pass the params for array of string like this
func2(['t1', 't1']); this work, but i want to extend the params info?
You can use a small helper function like this:
type
TInfo=record
s: string;
i: integer;
end;
function makeinfo(s:string;i:integer):TInfo;
begin
result.s:=s;
result.i:=i;
end;...
func1([makeinfo('test1', 1), makeinfo('test2', 2)]);Ludo
Declaring record constants inline in the code is not supported by FPC (regardless of…
Jonas Maebe wroteDeclaring record constants inline in the code is not supported by FPC (regardless of whether it's for an array parameter, an assignment or something else). There are no plans to add support for it either.
Ouch :P , bad news, but it save my trying time, thanks.
Zaher Dirkey
Thanks, but that is not my expected answer, my ask about "dynamic array of record" and…
Yes, it is good idea, i will try it :D
Best Regards
Zaher Dirkey
Thanks, but that is not my expected answer, my ask about "dynamic array of record" and…
That`s a nice idea.
You have to declare the parameter type independently of the function declaration. You can…
Howard are you saying FPC has dynamic arrays? Is it documented? I've been reading the documentation page by page and I've not seen any mention of it. I'm far from completing the reading by the way.
If dynamic arrays are part of FPC I couldn't be more delighted. I don't completely understand what they are exactly. Would I be right in saying they have the advantages of a linked list without the loss of speed that I so enjoy with arrays? Maybe linked lists are slow for me because of the way I wrote the code. The problem I have with arrays is that I often parse postscript vector art files. These files have to be read in a discovery mode approach because I don't know how many paths I will encounter nor know how many vertices will be in a path. As a result arrays are large enough to accommodate the largest path but are way overkill for a simple path.
My hope would be that I could use a dynamic array to hold just the number of vertices I discover in a path.
Thanks for sharing the code in your post. It fascinates me.
I'm eager to learn all I can about about the amazing things that can be done with FPC. To all those who have been building FPC, thank you. While I have been programming in pascal since 1986 almost daily I've relied on the basic features of the language. Time to stretch my mind.
Thomas Young
cell: 330-256-7064
mobile email:
Howard are you saying FPC has dynamic arrays? Is it documented?
http://wiki.freepascal.org/DYNAMIC_ARRAY
R.
Thank you.
Thomas Young
cell: 330-256-7064
mobile email:
Forgive me for being in wide-eyed wonder but my goodness this is more than a nice feature. Brilliant. I feel like a child who has played with toy blocks all these years and who now received keys to a ferrari.
Thomas Young
cell: 330-256-7064
mobile email:
Thomas Young wroteForgive me for being in wide-eyed wonder but my goodness this is more than a nice feature. Brilliant. I feel like a child who has played with toy blocks all these years and who now received keys to a ferrari.
You might get this feeling for often when you use FPC. I'm already developing inside the compiler, but still there is sometimes the feeling "Oh, shiny!".
Btw: Here is the link to the part where dynamic arrays are described in the language reference:
http://www.freepascal.org/docs-html/ref/refse14.html#QQ2-39-50 (which is a nice bed lecture by the way ;) )
Regards,
Sven