Re: pointers to arrays

2017-11-01 Thread Arnaud de Montard via 4D_Tech

> Le 31 oct. 2017 à 21:47, Kirk Brooks via 4D_Tech <4d_tech@lists.4d.com> a 
> écrit :
> 
> Peter,
> This is easy to do with local arrays and dynamic variables. It looks like
> you only need to build text arrays. You can declare a local array, ARRAY
> TEXT($aText2d;0;0). Then you can resize this to add more 'columns' as
> needed and populate them.

I'd choose that too: 2D arrays to grab imported data, listbox if display is 
needed. 
Creating records after will be easy and fast with array to selection. 
To convert an array text in array else, here's some code that I use: 


-- 
Arnaud de Montard 




**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Peter Mew via 4D_Tech
Hi Kirk
Yes all the arrays are Text Arrays.
My aim is to import all the data and load it into the various arrays. The
basic problem is that I dont know in advance, how much data there will be.
Think of it like this.
There maybe beween 1 and lets say 16 audio channels.
each audio channel maybe divided into between 1 and several hundred
segments. each boundry beween segments will have 14 parameters..
the only thing I know in advance is that each segment boundry will have 14
parameters,
I can read all the data, its just a case of filling the correct number of
arrays.
The User will be able to choose which of the upto 16 channels they want
view data for.
I will then transfer the contents of the appropriate arrays for the chosen
channel into a listbox for display
On the face of it, it should be fairly simple, its just not knowing how
many arrays are required in advance thats giving me the problems.
I shall look at your code and see if I can fit it to my requirements
Thanks
-pm

On Tue, Oct 31, 2017 at 8:47 PM, Kirk Brooks via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Peter,
> This is easy to do with local arrays and dynamic variables. It looks like
> you only need to build text arrays. You can declare a local array, ARRAY
> TEXT($aText2d;0;0). Then you can resize this to add more 'columns' as
> needed and populate them.
>
> Next you need to populate the listbox. First delete all the existing
> columns (if any) then insert the number of columns you need. To use dynamic
> vars you pass Nil for the column and header vars. Let's say you need 4
> columns, it looks like this:
>
> LISTBOX DELETE COLUMNS(*;"listboxName";1;LISTBOX GET NUMBER
> COLUMNS(*;"listboxName"))
>
> C_POINTER($nil)
>
> For($j;1;4)
>
> LISTBOX INSERT COLUMN (*;"listboxName"; $j; "col_"+string($j); $nil;
> "hdr_"+string($j); $nil)
>
> $colPtr:=object get pointer(Object named;"col_"+string($j))  //  now 4D has
> created a variable for the column and we can get its pointer
>
> COPY ARRAY($aText2d{$j};$colPtr->)  //  and copy the data to that array
>
> End for
>
> ​Even if you need mixed data types I'd still use text arrays for handling
> the display and user interface and do the data conversion on in the
> background. You can use the same approach with different types of arrays
> but it's a lot more work whereas converting to and from text is easy. ​And
> this works complied.
>
> D
> ​oes that make sense? ​Do I get your need correctly?
>
> On Tue, Oct 31, 2017 at 12:42 PM, Peter Mew via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
>
> > Thank You
> > And How do I create the Arrays in the First Place
> > -pm
> >
> >
> --
> Kirk Brooks
> San Francisco, CA
> ===
>
> *The only thing necessary for the triumph of evil is for good men to do
> nothing.*
>
> *- Edmund Burke*
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
>
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Kirk Brooks via 4D_Tech
Peter,
This is easy to do with local arrays and dynamic variables. It looks like
you only need to build text arrays. You can declare a local array, ARRAY
TEXT($aText2d;0;0). Then you can resize this to add more 'columns' as
needed and populate them.

Next you need to populate the listbox. First delete all the existing
columns (if any) then insert the number of columns you need. To use dynamic
vars you pass Nil for the column and header vars. Let's say you need 4
columns, it looks like this:

LISTBOX DELETE COLUMNS(*;"listboxName";1;LISTBOX GET NUMBER
COLUMNS(*;"listboxName"))

C_POINTER($nil)

For($j;1;4)

LISTBOX INSERT COLUMN (*;"listboxName"; $j; "col_"+string($j); $nil;
"hdr_"+string($j); $nil)

$colPtr:=object get pointer(Object named;"col_"+string($j))  //  now 4D has
created a variable for the column and we can get its pointer

COPY ARRAY($aText2d{$j};$colPtr->)  //  and copy the data to that array

End for

​Even if you need mixed data types I'd still use text arrays for handling
the display and user interface and do the data conversion on in the
background. You can use the same approach with different types of arrays
but it's a lot more work whereas converting to and from text is easy. ​And
this works complied.

D
​oes that make sense? ​Do I get your need correctly?

On Tue, Oct 31, 2017 at 12:42 PM, Peter Mew via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Thank You
> And How do I create the Arrays in the First Place
> -pm
>
>
-- 
Kirk Brooks
San Francisco, CA
===

*The only thing necessary for the triumph of evil is for good men to do
nothing.*

*- Edmund Burke*
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Peter Mew via 4D_Tech
OK
thanks
There will be a maximum of 16 passes through the loop, with a maximum of 14
arrays declared on each pass.
each array could have between 1 and a couple of hundred elements. it
depends on the size of the original document, from where all the original
data is imported. each one of the 14 arrays will be the same size, to be
displayed in a listbox
The final code will be compiled.
BTW this is v13 MAC Yosemite
Ill give it a try
thanks again
-pm

On Tue, Oct 31, 2017 at 7:29 PM, Peter Mew  wrote:

> Hi
> I want to achieve the following:
> To Loop through a block of code (the number of times will be determined
> elsewhere, but may well be different each time).
> Create a set of arrays that will have the same name + the loop counter,
> for each pass through the loop
> So pass 1 might create 3 arrays called Array101 Array201 Array301
> pass 2 would create arrays called Array102 Array202 Array302
> and so on
> the arrays would be filled with data by the code in the loop
>
> I then want to be able to reference these arrays, to retreive the data in
> the arrays according the loop number that created them
> So I might want to get the data for pass 2, from Array102 Array202
> Array302, and display it elsewhere.
>
> Im pretty sure I need to use pointers to accomplish this, but I dont know
> how.
> Could someone point (sic) me in the right direction
>
> Thanks
> -pm
>
>
>
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Chip Scheide via 4D_Tech
Peter,

IF your code will never be compiled the first code I sent will work, 
and you will be creating arrays 'on the fly', if you do this, I suggest 
you create local arrays, array names starting with a '$', so that they 
are thrown away at the end of the process/method.

IF you code will EVER be compiled, trying to create them on the fly 
will create 'issues'.
You can try using the listbox solution posted by Keith, or you can 
simply create a bunch of arrays and keep them around.

Then you can do what both Keith, and I showed you to get a pointer to 
the array(s) you need.
Of course for the predefined arrays to work, you will need to know what 
a maximum number you will need.


`Method : Bunch_of_Arrays
`n = some number, probably 10

Array Text(at_Array_Text_01;0)
Array Text(at_Array_Text_02;0)
...
Array Text(at_Array_Text_;0)

Array Longint(al_Array_Long_01;0)
Array Longint(al_Array_Long_02;0)
...
Array Longint(al_Array_Long_;0)

` for each type of array you will need



For the 2D approach, a 2D array you declare it:
Array Text($2D_Array_Name;Size_1;Size_2)

you reference it using:
2D_Array_Name{$Row}{$Column}

You can then resize it as needed

On Tue, 31 Oct 2017 19:54:33 +, Peter Mew via 4D_Tech wrote:
> If I read that correctly, that will create the arrays for pass 1 through
> the loop, but what about creating the arrays for pass 2, and any subsequent
> passes.
> I expected to create the arrays, as they were needed, for each pass.
> something like
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Chip Scheide via 4D_Tech
compiler declaration(s)

Array (Variable_Name;Size)

 is the type of the array you want, text, longint, etc

On Tue, 31 Oct 2017 19:42:42 +, Peter Mew via 4D_Tech wrote:
> Thank You
> And How do I create the Arrays in the First Place
> -pm
> 
> On Tue, Oct 31, 2017 at 7:32 PM, npdennis  wrote:
> 
>>> Im pretty sure I need to use pointers to accomplish this, but I dont
>> know how.
>> 
>> Try the command Get Pointer…
>> 
>> $p:=Get Pointer(“Array201”)
>> or
>> $x:=201
>> $p:=Get Pointer(“Array”+string($x))
>> 
>> However compiled you may need to have the arrays declared some place.
>> 
>> Neil
>> 
>> 
>> 
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Chip Scheide via 4D_Tech
some pseudo code to follow:
an out line would be:

if the code is not compiled the following will work, if it is (or is 
going to be) then you need to create the arrays before hand. For the 
example all arrays are text.

Array pointer($New_Array_Handles;0)

For ($i;1;$Number_Of_Arrays)
  $Array_Name:= "Array_"+String($i;"00) 
  $Array_Pointer := Get Pointer($Array_Name) `gives a pointer to 
Array_01, Array_02 ...

` assume all arrays are text
  Array Text($Array_Pointer->;0)

` depending on what you are doing you can add data here
  Insert in array($Array_Pointer->;$Where;$How_Many)
  for($ii;1;$data_size)
Array_Pointer->{$ii}:=$New_Data
  end for
` or
  Append to array($Array_Pointer->;$Data)
  
` or you can add the array pointer to another array to 
reference later
  Append to array($New_Array_Handles;$Array_Pointer) `adds pointer to 
new array
end for

To reference the specific element of an array through a pointer
$Array_Pointer->{$Element_Number}

To reference from the pointer array
$New_Array_Handles->{$Which_array}->{$Element_Number}

in some instances, you will find 4D chokes on second reference (context 
dependent) so you can use either of the following as well:
($New_Array_Handles->{$Which_array})->{$Element_Number}
  ` or in 2 steps
$Pointer_To_Array:=$New_Array_Handles->{$Which_array}
$Pointer_To_Array->{$Element_Number}

On Tue, 31 Oct 2017 19:29:18 +, Peter Mew via 4D_Tech wrote:
> Hi
> I want to achieve the following:
> To Loop through a block of code (the number of times will be determined
> elsewhere, but may well be different each time).
> Create a set of arrays that will have the same name + the loop counter, for
> each pass through the loop
> So pass 1 might create 3 arrays called Array101 Array201 Array301
> pass 2 would create arrays called Array102 Array202 Array302
> and so on
> the arrays would be filled with data by the code in the loop
> 
> I then want to be able to reference these arrays, to retreive the data in
> the arrays according the loop number that created them
> So I might want to get the data for pass 2, from Array102 Array202
> Array302, and display it elsewhere.
> 
> Im pretty sure I need to use pointers to accomplish this, but I dont know
> how.
> Could someone point (sic) me in the right direction
> 
> Thanks
> -pm
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread npdennis via 4D_Tech
> but that doesnt work, hence my question

If you want to run compiled you will need to use a list box to create dynamic 
arrays… or declare every possible combination you will use in a method and use 
get pointer…

However in your case you might be able to use a 2D array, or depending on what 
version of 4D you are using you may be able to use a C_Object

Neil

--
Neil Dennis
4D Developer since 1990

**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays (and List Box Basics)

2017-10-31 Thread Keith Culotta via 4D_Tech
A past discussion mentioned creating arrays on the fly using a Listbox command 
that creates columns.


This is for an array listbox.
http://livedoc.4d.com/4D-Language-Reference-16.2/List-Box/LISTBOX-INSERT-COLUMN.301-3433513.en.html
 C_POINTER($NilPtr)
 LISTBOX INSERT 
COLUMN(*;"MyListBox";1;"MyNewColumn";$NilPtr;"MyNewHeader";$NilPtr)
 ColPtr:=OBJECT Get pointer(Object named;"MyNewColumn")
 ARRAY TEXT(ColPtr->;10)

Keith - CDI

> On Oct 31, 2017, at 2:42 PM, Peter Mew via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> Thank You
> And How do I create the Arrays in the First Place
> -pm
> 
> On Tue, Oct 31, 2017 at 7:32 PM, npdennis  wrote:
> 
>>> Im pretty sure I need to use pointers to accomplish this, but I dont
>> know how.
>> 
>> Try the command Get Pointer…
>> 
>> $p:=Get Pointer(“Array201”)
>> or
>> $x:=201
>> $p:=Get Pointer(“Array”+string($x))
>> 
>> However compiled you may need to have the arrays declared some place.
>> 
>> Neil
>> 
>> 
>> 
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Peter Mew via 4D_Tech
OK
If I read that correctly, that will create the arrays for pass 1 through
the loop, but what about creating the arrays for pass 2, and any subsequent
passes.
I expected to create the arrays, as they were needed, for each pass.
something like

For ($i;1;Size of array(EDLBlockArray))
If ($i<10)
stringi:="0"+String($i)
Else
stringi:=String($i)
End if

FileName:="FileName"+stringi
ARRAY TEXT(FileName;0)
InfadeMS:="InfadeMS"+stringi
ARRAY TEXT(InfadeMS;0)
InFadeSamp:="InFadeSamp"+stringi
ARRAY TEXT(InFadeSamp;0)
OutfadeMS:="OutfadeMS"+stringi
ARRAY TEXT(OutfadeMS;0)
OutFadeSamp:="OutFadeSamp"+stringi
ARRAY TEXT(OutFadeSamp;0)
SourceStartMS:="SourceStartMS"+stringi
ARRAY TEXT(SourceStartMS;0)
SourceStartSamp:="SourceStartSamp"+stringi
ARRAY TEXT(SourceStartSamp;0)
SourceEndMS:="SourceEndMS"+stringi
ARRAY TEXT(SourceEndMS;0)
SourceEndSamp:="SourceEndSamp"+stringi
ARRAY TEXT(SourceEndSamp;0)
DestStartMS:="DestStartMS"+stringi
ARRAY TEXT(DestStartMS;0)
DestStartSamp:="DestStartSamp"+stringi
ARRAY TEXT(DestStartSamp;0)
DurationMS:="DurationMS"+stringi
ARRAY TEXT(DurationMS;0)
DurationSamp:="DurationSamp"+stringi
ARRAY TEXT(DurationSamp;0)
Gain:="Gain"+stringi
ARRAY TEXT(Gain;0)
end for

but that doesnt work, hence my question
-pm

On Tue, Oct 31, 2017 at 7:47 PM, npdennis  wrote:

> And How do I create the Arrays in the First Place
>
>
> If you are running compiled you I think will need to type the arrays in a
> method someplace so the compiler knows about the arrays. I know that some
> variable types don’t need compiler declarations, but I think arrays do.
>
> // Some method maybe a COMPILER_ARRAY method
> Array text (array1;0)
> Array text (array2;0)
> Array text (array3;0)
> Array text (array4;0)
> // add the arrays you will use here
>
>
>
> // Method to assign the arrays
>
> $p:=Get Pointer(“array”+string($1)) // assuming you pass in the array
> number such as one
>
> // Then use the pointer -> wherever you would use the array
>
> Array Text($p->;20)
> $p->{1}:=“One"
>
> // Or maybe something like
>
> Selection To Array([Table]Field;$p->)
>
>
>
> Neil
>
>
> --
> Neil Dennis
> 4D Developer since 1990
>
>
>
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread npdennis via 4D_Tech
> And How do I create the Arrays in the First Place

If you are running compiled you I think will need to type the arrays in a 
method someplace so the compiler knows about the arrays. I know that some 
variable types don’t need compiler declarations, but I think arrays do.

// Some method maybe a COMPILER_ARRAY method
Array text (array1;0)
Array text (array2;0)
Array text (array3;0)
Array text (array4;0)
// add the arrays you will use here



// Method to assign the arrays

$p:=Get Pointer(“array”+string($1)) // assuming you pass in the array number 
such as one

// Then use the pointer -> wherever you would use the array

Array Text($p->;20)
$p->{1}:=“One"

// Or maybe something like

Selection To Array([Table]Field;$p->)



Neil


--
Neil Dennis
4D Developer since 1990


**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread Peter Mew via 4D_Tech
Thank You
And How do I create the Arrays in the First Place
-pm

On Tue, Oct 31, 2017 at 7:32 PM, npdennis  wrote:

> > Im pretty sure I need to use pointers to accomplish this, but I dont
> know how.
>
> Try the command Get Pointer…
>
> $p:=Get Pointer(“Array201”)
> or
> $x:=201
> $p:=Get Pointer(“Array”+string($x))
>
> However compiled you may need to have the arrays declared some place.
>
> Neil
>
>
>
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: pointers to arrays

2017-10-31 Thread npdennis via 4D_Tech
> Im pretty sure I need to use pointers to accomplish this, but I dont know how.

Try the command Get Pointer…

$p:=Get Pointer(“Array201”)
or
$x:=201
$p:=Get Pointer(“Array”+string($x))

However compiled you may need to have the arrays declared some place.

Neil


**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**