Recent

Author Topic: (Solved)Listbox to array error  (Read 3927 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #15 on: November 29, 2020, 07:21:13 pm »
I already have Types in my use clause. I'm doing some graphics.This is copied out of the program.

Code: Pascal  [Select][+][-]
  1.  
  2.   Type
  3.  
  4.  TStringDynArray = array of string;
  5.  
  6. procedure TForm1.GenericArrayLoad(out theArray: TStringdynArray; const aBox: TListBox);
  7.  begin
  8.    theArray := aBox.Items.ToStringArray;
  9.  end;          
  10.  
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Listbox to array error
« Reply #16 on: November 29, 2020, 07:25:06 pm »
I already have Types in my use clause [...]

Then you don't need to declare TStringDynArray again; it's already declared inside the Types unit.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #17 on: November 29, 2020, 07:29:48 pm »
took out the declaration and I still get the error:

unit1.pas(1678,27) Error: identifier idents no member "ToStringArray"
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #18 on: November 29, 2020, 07:40:17 pm »
 AS I understand it theArray := aBox.Items.ToStringArray;    is assigning the tstringlist of the listbox ABOX to a dynamic array. That is if it worked.

Therefore, I should be able to go the other way with something like this:

    Listbox1.items := ToStringArray; ?   
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Listbox to array error
« Reply #19 on: November 29, 2020, 07:45:29 pm »
took out the declaration and I still get the error:

unit1.pas(1678,27) Error: identifier idents no member "ToStringArray"

Strange. Please, test the attached project and see if it also fails; it doesn't here.

AS I understand it the
Code: Pascal  [Select][+][-]
  1. Array := aBox.Items.ToStringArray;
is assigning the tstringlist of the listbox ABOX to a dynamic array. That is if it worked.

Therefore, I should be able to go the other way with something like this:
Code: Pascal  [Select][+][-]
  1. Listbox1.items := ToStringArray;

No, because ToStringArray is a method of the TStrings class. Besides, think of what that would do: it would destroy the current Items and replace them with ... what? :o

And what TStrings.ToStringArray does is to get the TStrings strings and copy them over to a dynamic array, a string at a time. That's it.

ETA: This is how it's done, in fact (taken from stringl.inc):
Code: Pascal  [Select][+][-]
  1. function TStrings.ToStringArray(aStart,aEnd : Integer): TStringDynArray;
  2. Var
  3.   I : Integer;
  4. begin
  5.   Result:=Nil;
  6.   if aStart>aEnd then exit;
  7.   SetLength(Result,aEnd-aStart+1);
  8.   For I:=aStart to aEnd do
  9.     Result[i-aStart]:=Strings[i];
  10. end;
« Last Edit: November 29, 2020, 07:54:27 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #20 on: November 29, 2020, 08:19:43 pm »
ok I will will take a few.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #21 on: November 29, 2020, 08:27:16 pm »
Same error: unit1.pas(55,26) Error: identifier idents no member "ToStringArray"

I think there is a difference between windows and UNIX.
« Last Edit: November 29, 2020, 08:29:26 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Thaddy

  • Hero Member
  • *****
  • Posts: 14371
  • Sensorship about opinions does not belong here.
Re: Listbox to array error
« Reply #22 on: November 29, 2020, 08:29:32 pm »
Same error: unit1.pas(55,26) Error: identifier idents no member "ToStringArray"
You need:
1) fpc 3.2.0. Not any older version, in that case YOU made the mistake. Old crap is nice for old people like me, not for starters.
2) include sysutils and types in the uses clause.
3) No, there is no difference between Windows and Linux in this case....
The documentation link assumes 3.2.0 since that is the current release.
« Last Edit: November 29, 2020, 08:38:35 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #23 on: November 29, 2020, 08:35:18 pm »
@Thaddy

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig

This is my use clause:

uses
  Buttons,  clipbrd,  Classes,   Controls,
  Dialogs,  ExtCtrls, FileUtil,  Forms,
  Graphics, SysUtils, StrUtils,  StdCtrls, Menus,
  Types, LazFileUtils;           

Willing to post the code.               

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Thaddy

  • Hero Member
  • *****
  • Posts: 14371
  • Sensorship about opinions does not belong here.
Re: Listbox to array error
« Reply #24 on: November 29, 2020, 08:39:26 pm »
No idea why it does not work for you. I tested it.
But code is always welcome because it makes it a lot easier to help you.
(not only me but also others like Lucamar)
« Last Edit: November 29, 2020, 08:44:58 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #25 on: November 29, 2020, 08:42:50 pm »
Ok Thaddy I'lll post. take a bit
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Listbox to array error
« Reply #26 on: November 29, 2020, 08:43:59 pm »
Willing to post the code.               

Yes, please, do it. It should be working, so there must be something else preventing it.

Though for my test project failing for you there must be something very wrong in your installation and that is more difficult to "debug" through forum posts %)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #27 on: November 29, 2020, 08:53:34 pm »
You need a sub-dir under the installation dir with two small text files. there are really config files for the program.

It will compile I think but you need the Dataset to run. Willing to post the Dataset. The Dataset is just a bunch of text files, zipped 150KB



FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Listbox to array error
« Reply #28 on: November 29, 2020, 09:00:30 pm »
Did you forget to post the code or is it "coming soon"(tm)? :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox to array error
« Reply #29 on: November 29, 2020, 09:05:12 pm »
oh I thought I did. Sorry.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018