С помощью компонента Memo заполнить строковый массив. Вывести в компоненты Edit самую длинную и самую короткую строку из массива — Delphi(Делфи)

unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TForm2 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.Button1Click(Sender: TObject);
var ar_string:array of string;
    smin,smax:string;
    count:integer;
begin
setlength(ar_string,memo1.Lines.Count);
for count := 0 to memo1.Lines.Count-1 do
  ar_string[count]:=memo1.Lines[count];  
if length(ar_string)>0 then
  begin
    smin:=ar_string[0];
    smax:=ar_string[0];
    for count := 1 to length(ar_string) - 1 do
      begin
        if length(smin)>length(ar_string[count]) then
          smin:=ar_string[count];
        if length(smax)<length(ar_string[count]) then
          smax:=ar_string[count];
      end;
    edit1.Text:=smin;
    edit2.Text:=smax;
  end
else
  showmessage('Массив пустой');
end;
 
end.

Leave a Comment

− 2 = 4