Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-02

Can I assign items in an array all at once in FreePascal?

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Aradeonas

Hi, As question explained here
http://stackoverflow.com/questions/6493727/can-i-assign-items-in-an-array-all-at-once-in-delphi-pascal and the easiest answer is :

type
  TIntArray =arrayof integer;procedure TForm1.Button1Click(Sender:
  TObject);var MyArr: TIntArray;begin MyArr :=
  TIntArray.Create(10,20,30,40);end;

But problems are : Lazarus doesnt recognize Create for array but FPC will compile it but it seems it doesnt work so I want to ask what should I do for?assign items in an array all at once in FreePascal?

Regards, Ara

http://www.fastmail.com - A fast, anti-spam email service. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160206/e7d43c05/attachment.html>

Reply by email

Michael Van Canneyt
to Aradeonas
Aradeonas wrote 11 lines
Hi, As question explained here http://stackoverflow.com/questions/6493727/can-i-assign-items-in-an-array-all-at-once-in-delphi-pascal and the easiest answer is : > type TIntArray =arrayof integer;procedure TForm1.Button1Click(Sender: TObject);var MyArr: TIntArray;begin MyArr := TIntArray.Create(10,20,30,40);end; But problems are : Lazarus doesnt recognize Create for array but FPC will compile it but it seems it doesnt work so I want to ask what should I do for?assign items in an array all at once in FreePascal?

The above is the only correct solution.

If the Lazarus codetools do not recognize this, then a bug report should be created for the IDE codetools.

Michael.

Reply by email

Michael Van Canneyt
to Aradeonas
Aradeonas wrote
Michael can I ask why we cant do something like this : > ?MyArr :=[10, 20, 30, 40]; ??

Because of 2 reasons:

1. Delphi introduced the create constructor.

2. A literal such as [10,20,30,40] is a set in pascal, not an array.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt
"Michael Van Canneyt" wrote 15 lines
On Sat, 6 Feb 2016, Aradeonas wrote: > Michael can I ask why we cant do something like this : >> >> MyArr :=[10, 20, 30, 40]; Because of 2 reasons: 1. Delphi introduced the create constructor. 2. A literal such as [10,20,30,40] is a set in pascal, not an array.

The answer is no longer correct with current Delphi versions. It now is "because we haven't implemented it yet".

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160206/30048695/attachment.html>

Reply by email

Aradeonas
to Sven Barth: The answer is no longer correct with current Delphi versions. It now is "because we…

I like this one more :

It now is "because we haven't implemented it yet"

Because :

A literal such as [10,20,30,40] is a set in pascal, not an array.

Is not a good one I think. For example this one works :

function Test(Arr:array of integer); Usage: Test([1,2,3]);

Why it cant work for assigning a var but it can be used for parameters?

Regards, Ara

http://www.fastmail.com - Same, same, but different... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160206/06527eb3/attachment-0001.html>

Reply by email

Michael Van Canneyt
to Sven Barth: The answer is no longer correct with current Delphi versions. It now is "because we…
Sven Barth wrote 9 lines
> > Because of 2 reasons: > > 1. Delphi introduced the create constructor. > > 2. A literal such as [10,20,30,40] is a set in pascal, not an array. The answer is no longer correct with current Delphi versions. It now is "because we haven't implemented it yet".

Indeed. Well, I'm still on XE, the jump to XE 10 is for next month. Seems I'll have some reading up to do...

Disregarding the fact that they introduced now 2 syntaxes to initialize an array, I'm curious what Jonas is going to say, because I remember he always advocates that the type of an expression is determined by the terms/factors in the expression, not by what you assign it to.

For
['abc','def'] + ['ghi','jkl']
it is more or less clear.

But what is the type of this expression:
[1,2,3] + [4,5,6]
is it an array or a set ?

It probably means that they regard [] always as an array, and added some kind of automatic set-to-array type assignment compatiblity for types that somehow fit in a set.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt
"Michael Van Canneyt" wrote 22 lines
On Sat, 6 Feb 2016, Sven Barth wrote: >> >> Because of 2 reasons: >> >> 1. Delphi introduced the create constructor. >> >> 2. A literal such as [10,20,30,40] is a set in pascal, not an array. > > > The answer is no longer correct with current Delphi versions. It now is > "because we haven't implemented it yet". Indeed. Well, I'm still on XE, the jump to XE 10 is for next month. Seems I'll have some reading up to do... Disregarding the fact that they introduced now 2 syntaxes to initialize an array, I'm curious what Jonas is going to say, because I remember he

always advocates that the type of an expression is determined by the terms/factors in the expression, not by what you assign it to.

Show quoted text 11 lines
For ['abc','def'] + ['ghi','jkl'] it is more or less clear. But what is the type of this expression: [1,2,3] + [4,5,6] is it an array or a set ? It probably means that they regard [] always as an array, and added some kind of automatic set-to-array type assignment compatiblity for types

that somehow fit in a set.

Well... FPC is handling them special as well, after all we support open array parameters as well which clearly are no sets either. ;) They are parsed into an array constructor nodes and then converted into either an open array or a set by the node they're contained in. Support for normal arrays will simply(TM) mean the addition of additional special cases... (yes, it's easier said than done ;) )

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160207/88b15090/attachment.html>

Reply by email