Recent

Author Topic: I can't see the error  (Read 1960 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 2103
  • Compiler Developer
Re: I can't see the error
« Reply #30 on: August 03, 2020, 10:07:34 pm »
Both statements should fail, because using the array constructor Create with no arguments should not be allowed. In addition to that the second statement should complain about Create not being allowed...

rvk

  • Hero Member
  • *****
  • Posts: 4280
Re: I can't see the error
« Reply #31 on: August 03, 2020, 10:15:05 pm »
Both statements should fail, because using the array constructor Create with no arguments should not be allowed. In addition to that the second statement should complain about Create not being allowed...
It's new in 3.0.0

Dynamic array constructors
Overview: Support has been added for constructing dynamic arrays with class-like constructors.
Notes: Delphi-compatible.
More information: Only constructor name 'CREATE' is valid for dynamic arrays.
Examples: SomeArrayVar := TSomeDynArrayType.Create(value1, value2)

https://wiki.freepascal.org/FPC_New_Features_3.0.0

PascalDragon

  • Hero Member
  • *****
  • Posts: 2103
  • Compiler Developer
Re: I can't see the error
« Reply #32 on: August 03, 2020, 10:20:08 pm »
You are really trying me today, are you? :o

I am aware of dynamic array constructors. What should not work however is

Code: Pascal  [Select][+][-]
  1. TSomeArrayType.Create; // note no arguments!

as well as:

Code: Pascal  [Select][+][-]
  1. SomeArrayVar.Create(value1, value2); // variable NOT type!

BeniBela

  • Hero Member
  • *****
  • Posts: 753
    • homepage
Re: I can't see the error
« Reply #33 on: August 03, 2020, 10:24:08 pm »
When you call Create, you need to call Free afterwards to prevent memory leaks.

Though not for arrays, Create is a really bad name for array creation

rvk

  • Hero Member
  • *****
  • Posts: 4280
Re: I can't see the error
« Reply #34 on: August 03, 2020, 10:31:43 pm »
as well as:
Code: Pascal  [Select][+][-]
  1. SomeArrayVar.Create(value1, value2); // variable NOT type!
The following also compiles. Always has. It's only that T is nil that it will crash (but otherwise the effect is the same, calling Create constructor of an object, which you never want to do like this).
Code: Pascal  [Select][+][-]
  1. var
  2.   T: TObject;
  3. begin
  4.   T.Create; // <-- compiles

You are really trying me today, are you? :o
Me  %)
Well, I'll refrain from any more comments if one post of me gets you so upset like that (look at what post).

PascalDragon

  • Hero Member
  • *****
  • Posts: 2103
  • Compiler Developer
Re: I can't see the error
« Reply #35 on: August 03, 2020, 10:44:04 pm »
When you call Create, you need to call Free afterwards to prevent memory leaks.

Though not for arrays, Create is a really bad name for array creation

Tell that the Delphi devs... I'm glad that they saw reason later on and allowed the [ … ] syntax.

as well as:
Code: Pascal  [Select][+][-]
  1. SomeArrayVar.Create(value1, value2); // variable NOT type!
The following also compiles. Always has. It's only that T is nil that it will crash (but otherwise the effect is the same, calling Create constructor of an object, which you never want to do like this).
Code: Pascal  [Select][+][-]
  1. var
  2.   T: TObject;
  3. begin
  4.   T.Create; // <-- compiles

But that is not the same. In an object that is called like a regular method in this case (allowing you to change the state of the object) and if some object field should be accessed inside that method while T is Nil, well, though luck.
The Create for dynamic arrays is no method however, it's a compiler intrinsic (and as BeniBela said a really badly named one at that). It makes no sense at all to call it on a variable, because it does not allow you to change the state of the variable inside that constructor (no, arr := arr.Create(v1, v2); does not count as "changing the state" in this case).

You are really trying me today, are you? :o
Me  %)
Well, I'll refrain from any more comments if one post of me gets you so upset like that (look at what post).

No, it's the second time today. The first was this post in this very same thread.

kupferstecher

  • Sr. Member
  • ****
  • Posts: 406
Re: I can't see the error
« Reply #36 on: August 03, 2020, 11:16:50 pm »
The Create for dynamic arrays is no method however, it's a compiler intrinsic (and as BeniBela said a really badly named one at that).
I think its not worth the compatibility to add such 'features' to FPC.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2103
  • Compiler Developer
Re: I can't see the error
« Reply #37 on: August 03, 2020, 11:24:06 pm »
The Create for dynamic arrays is no method however, it's a compiler intrinsic (and as BeniBela said a really badly named one at that).
I think its not worth the compatibility to add such 'features' to FPC.

You are around 9 years too late for that ;)

kupferstecher

  • Sr. Member
  • ****
  • Posts: 406
Re: I can't see the error
« Reply #38 on: August 04, 2020, 01:09:08 pm »
 :D

Yes, I was more speeking in general~

 

TinyPortal © 2005-2018