Welcome to %s forums

BrainModular Users Forum

Login Register

[script] TstringList sizes

I need help on a Patch
Post Reply
23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 28 Jun 2010, 20:05

I have something i don't catch yet is how to handle stringList size.

usually I use 'Set capacity' on init of the script so that looks like

SL1.capacity := X;

or i pick commaText from an input.
but I notice to be able to set an item in the list, the list seems to first have a comma text. if i direct try ie:

SL1.strings[5] := 'blabla';

it returns me an error, , even if capacity is set above 5, whereas it will work if on init i defined a commatext, ie

SL1.commaText := 0,1,2,3,4,5,6,7,8; ect.. so that's quite boring if size change, or have to fill it...

Isn't there a simpler way? basically i want the script to catch a matrix size and be able to change some captions
relating the cliced index nb, but if i saved to a preset with a matrix where 5 cellz had caption set, the commain goes
back to script and i can change the 5 captions , but if iwanna set ie cell 8 wich as no caption i can't, even if i set
SL1.capacity to 8, cause the comma from matrix only goes to 5.

see what i mean, any mater as a tip?

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 28 Jun 2010, 20:09

hahaha, i'm facing exactly the same problem ;)

unfortunately, i haven't found a solution yet :(
Martin FLEURENT - Usine Developer - SDK maintainer

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 28 Jun 2010, 20:25

hehe arf, it was ok cause if had a full size init comma text, but con't know how to go outside range arf Olivier help us,

maybe gonna try to fill an array of string, but there must be a simple solution, that's not possible..
don't know arf this drives me crasy heehe. oooollliiiviiier!!

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 28 Jun 2010, 21:01

the solution:

Code: Select all

SL1.count
gives the total number of items in the StringList

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 28 Jun 2010, 21:09

mmmm yup i know SL1.count but that's read only, to get but not to set the size if im not wrong?

what we want is being able to set an item above SL1.count

ie a comma from a preset as 5 item, but we wanna set the 8th item.
SL1 pick the commatext from in, so SL1.count is 5, then even if we set SL1 Capacity to 8,
we can't modify the 8th element of SL1, cause the commatext only goes to 5, even if it's capacity is 8.

my solution for now was make an array of string of size 8, fill it with the 1-5 from comma in items, so if then if i try to set item 8
of stringArray, it works,( whereas i can't on stringlist )then reconstruct the commaout by concating each element of the string array + a comma in between.
that works but seems weird complex, ;) there must be simpler no?

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 28 Jun 2010, 22:39

I believe the problem we encounter is that the stringlist is a list of object, even if we change the capacity, we need to create object (strings in this case) for all members of the list

for now, i solved this problem with a procedure

Code: Select all

// S is a global string variable

Procedure ExtendStringList;
var id, count, i : Integer;
BEGIN
    id := Round(GetValue(new_caption_id));
    count := slCaptions.count;
    
    if (new_id >= count) then 
    begin
        slCaptions.capacity:= new_id + 1; 
        S := '';
        for i:= count to new_id + 1 do begin
               slCaptions.add(S);
        end;
    end;
END;
it extend the stringlist to the new capacity with some empty string

hope it help
Martin FLEURENT - Usine Developer - SDK maintainer

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 28 Jun 2010, 23:31

ok cool, thanks that's what i suposed, a bit sad, no such needs with arrays of strings...

think it's better than my system, i copy the list items to an array of string, that will work in any case and recompose the comma from the array, but that mean double internal use and old skool reconcating with comma. better format the new adds and use your technique.

funny i was also using the index as "max size" and you make me notice i forgot to add +1.will convert my system..

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 30 Jun 2010, 20:01

well done Martin!
Totally right.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests