Tuesday, January 26, 2016

Delphi Tutorial Listbox manipulate items

Delphi Tutorial Listbox manipulate items


In this video you can learn how to manipulate with Listbox items in Delphi.
You can learn how to add one, add multiple items, delete one or all items , so as save items to and load from text file.



Here is also code used in this video :
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Button3: TButton;
    Edit2: TEdit;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Add('Item - '+IntToStr(ListBox1.Items.Count));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ListBox1.Items.Add(Edit1.Text);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
i:Integer;
begin
ListBox1.Items.Clear; // clear all items in listbox first
for I := 1 to StrToInt(Edit2.Text) do
begin
ListBox1.Items.Add('Item - '+IntToStr(i));
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
ListBox1.Items.Delete(ListBox1.ItemIndex);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
ListBox1.Items.Clear;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
if SaveDialog1.Execute then
SaveDialog1.InitialDir:='C:\Temp\';
ListBox1.Items.SaveToFile(SaveDialog1.FileName);
ListBox1.Items.Clear;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
ListBox1.Items.Clear;
if OpenDialog1.Execute then
OpenDialog1.InitialDir:='C:\Temp\';
ListBox1.Items.LoadFromFile(OpenDialog1.FileName);
end;

end.

Music in video by :
bensound-theelevatorbossanova
www.bensound.com

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Search This Blog

Powered by Blogger.

Contributors

Text Widget