What inherent inability? I think you are misreading stuff here. There's absolutely no problem with populating a list box from an array. You just have your code all mixed up.
Here's code that correctly populates the list box from an array made by GetFileList:
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 449
Top = 266
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 212
ClientWidth = 431
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSListBox1: tMSListBox
Left = 0
Top = 0
Width = 431
Height = 212
Align = alClient
ItemHeight = 13
MultiSelect = True
TabOrder = 8
SelectedIndex = -1
ExplicitLeft = 22
ExplicitTop = 12
ExplicitWidth = 275
ExplicitHeight = 97
end
end
EndDialog>Dialog1
GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF
//To populate the list all we need to do is:
//SetDialogProperty>Dialog1,MSListBox1,Text,theList
//but since you want to see how to do it from an array
//lets waste time by exploding the list to an array and THEN
//populate the list box from that array:
//explode the list to an array:
Separate>theList,CRLF,anArray
//now walk the array and populate the list box, which is basically just turning the array back into a delimited string
Let>new_list=
Let>k=0
Repeat>k
Let>k=k+1
Let>this_item=anArray_%k%
Let>new_list=%new_list%%this_item%%CRLF%
Until>k=anArray_count
//now we have reconstructed a delimited string from an array we can use it to populate the listbox
SetDialogProperty>Dialog1,MSListBox1,Text,new_list
Show>Dialog1,r
If need an array just use Separate.
So after this:
Code: Select all
GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF
Do this:
And then if you want to loop through it:
Code: Select all
Let>k=0
Repeat>k
Let>k=k+1
Let>this_item=array_%k%
...
Until>k=array_count
To create an array from items that have been selected in the list box:
Code: Select all
//let's see which items were selected and create an array from them
GetDialogProperty>Dialog1,MSListBox1,SelectedItems,Selected_list
Separate>Selected_List,CRLF,array_of_selected_items
Now you have an array called array_of_selected_items and if you want to walk through it use the same loop structure as the example given above.
Putting it all together to create a multi-select list box of files in a folder populated via an array and then creating an array from the user selected items:
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 802
Top = 351
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 212
ClientWidth = 431
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSListBox1: tMSListBox
Left = 0
Top = 0
Width = 431
Height = 212
Align = alClient
ItemHeight = 13
MultiSelect = True
TabOrder = 0
SelectedIndex = -1
end
end
EndDialog>Dialog1
GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF
//To populate the list all we need to do is:
//SetDialogProperty>Dialog1,MSListBox1,Text,theList
//but since you want to see how to do it from an array
//lets waste time by exploding the list to an array and THEN
//populate the list box from that array:
//explode the list to an array:
Separate>theList,CRLF,anArray
//now walk the array and populate the list box, which is basically just turning the array back into a delimited string
Let>new_list=
Let>k=0
Repeat>k
Let>k=k+1
Let>this_item=anArray_%k%
Let>new_list=%new_list%%this_item%%CRLF%
Until>k=anArray_count
//now we have reconstructed a delimited string from an array we can use it to populate the listbox
SetDialogProperty>Dialog1,MSListBox1,Text,new_list
Show>Dialog1,r
//let's see which items were selected and create an array from them
GetDialogProperty>Dialog1,MSListBox1,SelectedItems,Selected_list
Separate>Selected_List,CRLF,array_of_selected_items
//breakpoint here - look in the watch list and you'll see your array items
**BREAKPOINT**
Run it in the editor and then at the breakpoint look in the watch list to see the array items created.