View Full Version : Some doubts in pascal language..
arthurprs
26-09-2007, 03:09 AM
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 ->
var uuu : array [0..1] of integer;
begin
uuu := ((1),(2));
Parcel
26-09-2007, 05:32 AM
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 ->
var uuu : array [0..1] of integer;
begin
uuu := ((1),(2));
const
uuu : array[0..1] of integer = (1,2);
:wink:
JSoftware
26-09-2007, 09:12 AM
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
arthurprs
26-09-2007, 05:52 PM
thx for the replys, for in look looks interesting when working with Tlist and other classes
is there a way to do that ?
var
lol : array [0..1] of Integer;
begin
lol := (3,2);
JSoftware
26-09-2007, 08:28 PM
onme answer.. no
you can't make multiple assignments to arrays in one statement without utilizing hacks :P
Mirage
27-09-2007, 05:19 AM
Why hacks?
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.
This will work even if TA - a dynamic array.
marcov
28-10-2007, 01:07 PM
- how use "for in" loops
Well, that is simple: don't.
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.
wodzu
30-10-2007, 02:22 PM
There are some pretty impressive hacks allowing to do this even on Delphi 7.
Check this out ;)
http://andy.jgknet.de/dlang/
arthurprs
30-10-2007, 05:45 PM
There are some pretty impressive hacks allowing to do this even on Delphi 7.
Check this out ;)
http://andy.jgknet.de/dlang/
really impresive
Ramjet
04-11-2007, 07:41 PM
// 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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.