Lazarus で、リストデータの移動処理を行ってみた
リストデータの受け渡しのための
データの移動追加の処理を行ってみた
環境
Ubuntu16
Lazarus 2.0.10
参考ページ
https://www.migaro.co.jp/contents/products/delphi400/tips/introduction/4_20/02/01.html
http://delfusa.main.jp/delfusafloor/archive/www.nifty.ne.jp_forum_fdelphi/faq/00055.htm
https://www.migaro.co.jp/contents/products/delphi400/tips/introduction/4_20/02/01.html
http://dp25299446.lolipop.jp/delphi_tips/tips0045.html
ポイント
リストにはListBoxを使う
・項目追加
ListBox.Items.Add(文字列)
・項目削除
ListBox.Items.Delete(番号);
選択している行の場合
ListBox.Items.Delete(ListBox.ItemIndex);
・選択しているデータ
ListBox1.Items[ListBox.ItemIndex]
・選択しているかの判断
if (ListBox.ItemIndex > -1) Then 選択されている else 選択されていない
・データの永続的処理(ロード、セーブ)
ListBox.Items.LoadFromFile(ファイル名);
ListBox.Items.SaveToFile(ファイル名);
・その他論理演算
等しい時 =
等くない時 <>
論理and and
プログラム
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption:='>';
Button2.Caption:='<';
Button4.Caption:='adddata';
Button5.Caption:='delete';
Button6.Caption:='save';
Button3.Visible:=False;
ListBox1.Items.Add('abc-1');
ListBox1.Items.Add('abc-2');
ListBox1.Items.Add('abc-3');
Button3Click(Sender);
if FileExists('listdata.txt') then
ListBox2.Items.LoadFromFile('listdata.txt');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox2.Items.Add(ListBox1.Items[ListBox1.ItemIndex]);
ListBox1.Items.Delete(ListBox1.ItemIndex);
Button3Click(Sender);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ListBox1.Items.Add(ListBox2.Items[ListBox2.ItemIndex]);
ListBox2.Items.Delete(ListBox2.ItemIndex);
Button3Click(Sender);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if (ListBox1.ItemIndex > -1) and (ListBox1.Items.Count <> 0) then
button1.Enabled := True
else
button1.Enabled := False;
if (ListBox2.ItemIndex > -1) and (ListBox2.Items.Count <> 0) then
begin
button2.Enabled := True;
button5.Enabled := True;
end
else
begin
button2.Enabled := False;
button5.Enabled := False;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ListBox2.Items.Add(edit2.Text);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
ListBox2.Items.Delete(ListBox2.ItemIndex);
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
ListBox2.Items.SaveToFile('listdata.txt');
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
if edit2.text <> '' then
button4.Enabled := True
else
button4.Enabled := False;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
edit1.Text:=ListBox1.Items[ListBox1.ItemIndex];
Button3Click(Sender);
end;
procedure TForm1.ListBox2Click(Sender: TObject);
begin
Button3Click(Sender);
end;