урок на делфи 47 - Срванить списки


задание на delphi. Сравниваем листобокс


unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,ActiveX;
type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
Button2: TButton;
ListBox3: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
{
пояснение по работе
https://youtu.be/o8Bq34M0O7E
}
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
ListBox3.Items.AddStrings(ListBox1.Items);
for i := 0 to ListBox2.Count-1 do
if ListBox3.Items.IndexOf(ListBox2.Items[i]) < 0 then
ListBox3.Items.Add(ListBox2.Items[i]);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
temp:TStringList;
i:integer;
begin
temp:=TStringList.Create;
temp.Sorted:=true;
temp.Duplicates:=dupIgnore;
temp.AddStrings(ListBox1.Items);
for I := 0 to ListBox2.Count-1 do
temp.Add(ListBox2.Items[i]);
ListBox3.Items.AddStrings(temp);
FreeAndNil(temp);
end;
end.



Скачать