Recent

Author Topic: err shrinked array returns old length  (Read 2381 times)

laggyluk

  • Jr. Member
  • **
  • Posts: 69
err shrinked array returns old length
« on: February 19, 2013, 12:27:02 am »
I'm trying to shrink dynamic array
both setlength and fillchar seem to change size to 0 when inspecting array in debugger but length() still returns old size. Do I need to keep track of array length on my own or is there a proper way to shrink it?
« Last Edit: February 19, 2013, 12:29:21 am by laggyluk »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: err shrinked array returns old length
« Reply #1 on: February 19, 2013, 12:41:49 am »
You don't need to free dynamic arrays. FreePascal does it itself.
But still it should work. If you set its length to 0 with SetLength(array, 0); then Length(array) should return 0.

EDIT: Can you show the code?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: err shrinked array returns old length
« Reply #2 on: February 19, 2013, 05:14:56 am »
If you setlength() array to 0, then length() should tell you 0 aswell. Fillchar() modifies data inside, does not and should not affect array length. Dynamic array such as string is good example for fillchar
Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var s: string;
begin
  setlength(s, 10);
  fillchar(s[1], 10, '-'); // Makes s = '----------'
  caption:=s;
end;

laggyluk

  • Jr. Member
  • **
  • Posts: 69
Re: err shrinked array returns old length
« Reply #3 on: February 19, 2013, 08:41:14 am »
bug in my code  :-[

 

TinyPortal © 2005-2018