Steve88
Steve88

Reputation: 2416

Delphi Listbox+CheckListbox

I'm working on a mp3 sending program. I'm using a listbox to display a simple list of mp3 filenames(1.mp3,2.mp3,3.mp3 etc.)and a checklistbox where the connections(ip adress1,ip adress2)are. I want to know how can i save the listbox items with the checklistbox checked items as (links)? For example, if I want to send the 1.mp3 to ipadress1 and ipadress2, then the 2.mp3,3.mp3 for only ipadress2 etc..) I want to use a "File sending" button to save it to some txt files. Any idea?T hanks for the answers!

procedure TForm1.ListBox1Click(Sender: TObject);
 var
Item : TStringList;
I: Integer;
begin
 if ListBox1.ItemIndex = -1 then
  Exit ;
 if Assigned(ListBox1.Items.Objects[ListBox1.ItemIndex]) then
  Item := ListBox1.Items.Objects[ListBox1.ItemIndex] as TStringList
 else
 begin
   Item := TStringList.Create ;
   ListBox1.Items.Objects[ListBox1.ItemIndex] := Item;
 end ;
for I := 0 to CheckListBox1.Items.Count - 1 do
 CheckListBox1.Checked[I] := False; 
for I := 0 to Item.Count - 1 do
CheckListBox1.Checked[CheckListBox1.Items.IndexOf(Item[I])] := True; 
end;

procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
var
Item : TStringList;
I    : Integer;
begin
if ListBox1.ItemIndex = -1 then
begin
  ShowMessage('Select the mp3 first!');
  Exit ;
  end ;
 if Assigned(ListBox1.Items.Objects[ListBox1.ItemIndex]) then
 Item := ListBox1.Items.Objects[ListBox1.ItemIndex] as TStringList
 else
 begin
  Item := TStringList.Create;
  ListBox1.Items.Objects[ListBox1.ItemIndex] := Item;
end;
Item.Clear;
 for I := 0 to CheckListBox1.Items.Count - 1 do
 if CheckListBox1.Checked[I] then
  Item.Add(CheckListBox1.Items[I]);
end;

Upvotes: 0

Views: 4338

Answers (2)

Zeina
Zeina

Reputation: 1603

You could use an xml file if you have some additional options. You can add attributes as much as you want.

<Body>
  <F1.mp3 ipaddress1="True" ipaddress2="False"/>
  <F2.mp3 ipaddress1="False" ipaddress2="True"/>
</Body>

Upvotes: 2

Darkerstar
Darkerstar

Reputation: 932

You can save it to ini file. I think it fits your requirement.

use mp3 filename as section name, ip as name=value pair

[1.mp3]
ip1=1
ip2=1

[2.mp3]
ip2=1
ip4=1

Upvotes: 1

Related Questions