Recent

Author Topic: DynArrays, copy, parameters. And Dokumentation  (Read 736 times)

winni

  • Hero Member
  • *****
  • Posts: 2122
DynArrays, copy, parameters. And Dokumentation
« on: November 15, 2020, 08:21:13 pm »
Hi!

Just forgot one parameter in copy (DyArray, ... ) and found this in the doc:

In Delphi mode, the Count argument can be omitted. In that case, the string (or dynamic array) is copied from the position Index till the end of the string or array.

For DynArrays this is also true for {$mode objfpc} but nowhere documented.

With DynArray I also can do a complete copy:

DynArrayCopy := copy (DynArray);

This is documented nowhere.

Talking about fpc 3.04


And the documentation:

Pressing F1 on copy then nothing happens - like with all the other system functions.
Pressing Alt +  CursorUp  then nothing happens - like with all the other system functions.

At least there should be a message, how or where to look.

Winni






Zoran

  • Hero Member
  • *****
  • Posts: 1643
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DynArrays, copy, parameters. And Dokumentation
« Reply #1 on: November 15, 2020, 09:53:22 pm »

In Delphi mode, the Count argument can be omitted. In that case, the string (or dynamic array) is copied from the position Index till the end of the string or array.

For DynArrays this is also true for {$mode objfpc} but nowhere documented.


Not only for dynamic arrays, but also for strings.
Nowhere documented, but Copy without third argument works for strings in objfpc mode as well.

jamie

  • Hero Member
  • *****
  • Posts: 4052
Re: DynArrays, copy, parameters. And Dokumentation
« Reply #2 on: November 15, 2020, 10:02:47 pm »
The only true wisdom is knowing you know nothing

Zoran

  • Hero Member
  • *****
  • Posts: 1643
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DynArrays, copy, parameters. And Dokumentation
« Reply #3 on: November 15, 2020, 10:28:55 pm »
It actually works in all modes, behave same.

I reported it: bug 38086

Zoran

  • Hero Member
  • *****
  • Posts: 1643
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DynArrays, copy, parameters. And Dokumentation
« Reply #4 on: November 15, 2020, 10:40:18 pm »
Further test:

It works with AnsiString type, but it does not work with ShortString, not even in Delphi mode.
This is also undocumented (according to the documentation, you can assume it will work in delphi mode with ShortString too).

winni

  • Hero Member
  • *****
  • Posts: 2122
Re: DynArrays, copy, parameters. And Dokumentation
« Reply #5 on: November 15, 2020, 10:57:22 pm »
Ooops. Opened Pandora's Box.

Zoran you are right.
One should assume that it is also possible for ShortStrings.
But you get a compiler message you have a little bit to think about:

Code: Pascal  [Select][+][-]
  1. var  s1,s2 : shortString;
  2. ...
  3. s1 := copy(s2, 23);  

The compiler tells you:
Error: Type mismatch

He means: string <>  shortString

That's sometimes true.
But often NOT.

Winni

PascalDragon

  • Hero Member
  • *****
  • Posts: 2611
  • Compiler Developer
Re: DynArrays, copy, parameters. And Dokumentation
« Reply #6 on: November 16, 2020, 09:57:55 am »
One should assume that it is also possible for ShortStrings.
But you get a compiler message you have a little bit to think about:

It's fixed in trunk. And I've already found the revision that I'll need to merge back to 3.2.1. ;)

PascalDragon

  • Hero Member
  • *****
  • Posts: 2611
  • Compiler Developer
Re: DynArrays, copy, parameters. And Dokumentation
« Reply #7 on: November 28, 2020, 05:08:50 pm »
And FPC 3.2.1 now handles two parameter Copy for ShortString correctly as well. :)

 

TinyPortal © 2005-2018