мне надо сделать описание программульки, щас покажу код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Label1: TLabel;
Panel1: TPanel;
Memo1: TMemo;
Label2: TLabel;
procedure ListBox2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ListBox2Click(Sender: TObject);
var i, FNum: Integer;
s: String;
begin
if ListBox2.Selected[0] then
begin
// Создание списка
Memo1.Clear;
Memo1.Lines.Add('var List: TStringList; // Описание переменой');
Memo1.Lines.Add('...');
Memo1.Lines.Add('List:=TStringList.Create; // Создание объекта');
ListBox1.Clear;
end;
if ListBox2.Selected[1] then
begin
// Добавление элемента
Randomize;
Memo1.Clear;
s:=InputBox('Внимание','Строка:','Новая строка');
Memo1.Lines.Add('List.Add('''+s+''');');
ListBox1.Items.Add(s);
end;
if ListBox2.Selected[2] then
begin
// Удаление элемента
Memo1.Clear;
s:=InputBox('Внимание','Номер строки:','0');
Memo1.Lines.Add('List.Delete('+s+'); // Удаляем строку номер 0');
if ListBox1.Count>0 then ListBox1.Items.Delete(StrToInt(s));
end;
if ListBox2.Selected[3] then
begin
// Выборка элемента из списка
Memo1.Clear;
s:=InputBox('Внимание','Номер строки:','0');
Memo1.Lines.Add('Write(List.Strings['+s+']); // Выводим элемент номер 0');
if ListBox1.Count>0 then
Application.MessageBox(pchar(ListBox1.Items.Strings[StrToInt(s)]),'Список',0);
end;
if ListBox2.Selected[4] then
begin
// Поиск по списку
Memo1.Clear;
s:=InputBox('Внимание','Строка:','Новая строка');
Memo1.Lines.Add('var i, FNum: Integer;');
Memo1.Lines.Add('...');
Memo1.Lines.Add('FNum:=-1;');
Memo1.Lines.Add('for i:=0 to List.Count do');
Memo1.Lines.Add(' if List.Strings[i]=''Строка поиска'' then');
Memo1.Lines.Add(' begin FNum:=i; break; end;');
Memo1.Lines.Add('Write(FNum); // Выводим номер найденного элемента');
FNum:=-1;
for i:=0 to ListBox1.Count do
if ListBox1.Items.Strings[i]=s then
begin FNum:=i; break; end;
Application.MessageBox(pchar(IntToStr(FNum)),'Список',0);
end;
if ListBox2.Selected[5] then
begin
// Сортировка списка
Memo1.Clear;
Memo1.Lines.Add('List.Sort;');
Memo1.Lines.Add(' // Сортировка списка');
ListBox1.Sorted:=true;
ListBox1.Sorted:=false;
end;
if ListBox2.Selected[6] then
begin
// Очистка списка
Memo1.Clear;
Memo1.Lines.Add('List.Clear;');
Memo1.Lines.Add(' // Очистка списка');
ListBox1.Clear;
end;
end;
end.
Как видищь он с комментами, но их мало.
|