урок на делфи 26 - Поиск самой длинной строки


задание на 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;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Label1: TLabel;
Memo1: TMemo;
Label2: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,max_dlina:integer;
max_stroka:string;
begin
max_dlina:=0;
for I := 0 to ListBox1.Count-1 do
begin
if Length(ListBox1.Items[i])>max_dlina then
begin
max_stroka:=ListBox1.Items[i];
max_dlina:=Length(ListBox1.Items[i]);
end;
end;
Label1.Caption:=max_stroka;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i,max_dlina:integer;
max_stroka:string;
begin
max_dlina:=0;
for I := 0 to Memo1.Lines.Count-1 do
begin
if Length(Memo1.Lines[i])>max_dlina then
begin
max_stroka:=Memo1.Lines[i];
max_dlina:=Length(Memo1.Lines[i]);
end;
end;
Label2.Caption:=max_stroka;
end;
end.




Скачать