Im advancing in pascal but i don't know some things like...
- how use "for in" loops
- a const of arrays
- is there a way to do something like ->
[pascal]var uuu : array [0..1] of integer;
begin
uuu := ((1),(2));[/pascal]
Im advancing in pascal but i don't know some things like...
- how use "for in" loops
- a const of arrays
- is there a way to do something like ->
[pascal]var uuu : array [0..1] of integer;
begin
uuu := ((1),(2));[/pascal]
From brazil (:
Pascal pownz!
[pascal]Originally Posted by arthurprs
const
uuu : array[0..1] of integer = (1,2);
[/pascal]
What you see is what you do.
<br />
<br />Sorry, I'm not English well.
for in can be used to enumerate simple types and userdefined classes alike. Simple types can include chars for strings, elements in a simple array, and something else.. enums or sets I think and a normal TList+TStringlist
For classes you have to override a function called GetEnumerator which should return a class which should inherit some enumerator. Just look at TList's implementation
Peregrinus, expectavi pedes meos in cymbalis
Nullus norvegicorum sole urinat
thx for the replys, for in look looks interesting when working with Tlist and other classes
is there a way to do that ?
Code:var lol : array [0..1] of Integer; begin lol := (3,2);
From brazil (:
Pascal pownz!
onme answer.. no
you can't make multiple assignments to arrays in one statement without utilizing hacks
Peregrinus, expectavi pedes meos in cymbalis
Nullus norvegicorum sole urinat
Why hacks?
This will work even if TA - a dynamic array.Code:type TA = array[0..5] of Integer; function GetA(const aa: array of Integer): TA; var i: Integer; begin Assert(High(aa) <= High(TA), 'Too many parameters'); for i := 0 to High(aa) do Result[i] := aa[i]; end; var a: TA; begin a := GetA([5, 10, 20, 30, 40, 50]); end.
Well, that is simple: don't.Originally Posted by arthurprs
That is a pretty superficial extension, and the fact that older Delphi's and FPC don't support them is a good reason to avoid it like the plague.
It has one nice application though, iterating over an anonymous set.
There are some pretty impressive hacks allowing to do this even on Delphi 7.
Check this out
http://andy.jgknet.de/dlang/
really impresiveOriginally Posted by wodzu
From brazil (:
Pascal pownz!
Code:// Free Pascal {$assertions on} procedure stuffints( var a: array of longint; const b: array of longint); var i: word; begin assert(high(b)<=high(a), 'Too many args to stuffints.' ); for i := low(b) to high(b) do a[i] := b[i]; end; var a: array[1..5] of longint; ad: array of longint; begin stuffints( a, [11,22,33,44,55] ); setlength( ad, 3 ); stuffints( ad, [22,33,44] ); end.
Bookmarks