我正在制作一个mp3发送程序。我正在使用一个列表框来显示一个简单的mp3文件名列表(1.mp3,2.mp3,3.mp3等)以及一个连接(ip adress1,ip adress2)所在的checklistbox。我想知道我如何保存列表框项目与checklistbox检查项目为(链接)?例如,如果我想将1.mp3发送到ipadress1和ipadress2,那么2.mp3,3.mp3仅适用于ipadress2等。)我想使用“文件发送”按钮将其保存到某些txt文件。有什么想法吗?谢谢你的答案!
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;
答案 0 :(得分:2)
如果您有其他选项,可以使用xml文件。 您可以根据需要添加属性。
<Body>
<F1.mp3 ipaddress1="True" ipaddress2="False"/>
<F2.mp3 ipaddress1="False" ipaddress2="True"/>
</Body>
答案 1 :(得分:1)
您可以将其保存到ini文件中。我认为这符合您的要求。
使用mp3文件名作为部分名称,ip作为名称=值对
[1.mp3]
ip1=1
ip2=1
[2.mp3]
ip2=1
ip4=1