Программа не позволяет пользователю вводить в Edit'ы и StringGrid буквы, символы и прочую чепуху.
Code
unit laba3;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
I,J: integer;
implementation
{$R *.dfm}
procedure TForm1.Edit1Change(Sender: TObject);
begin
If (StrToInt(Edit1.Text)>20) OR (StrToInt(Edit1.Text)<=0)
then begin ShowMessage('Выход за границы массива!');
Edit1.Text:='20';
end;
StringGrid1.ColCount:=StrToInt(Edit1.Text)+1;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
SIZE=20;
var
a: array[1..SIZE] of integer;
n: integer;
found: boolean;
i,m: integer;
begin
{ввод числа элементов массива n<20}
n:=StrToInt(Edit1.text);
{ввод массива }
for i:=1 to n-1 do
a[i]:=StrToInt(StringGrid1.Cells[i,1]);
{ввод искомого элемента массива}
m:=StrToInt(Edit2.text);
{процедура поиска в массиве}
found:=false;
i:=1;
repeat
if a[i]=m then
found:=true
else
i:=i+1;
until (i>n) or (found = true);
if found=true then
ShowMessage('Совпадение с элементом номер '+ IntToStr(i)+#13+
'Поиск успешно завершен')
else
ShowMessage('Заданный элемент не найден!');
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9': ;
else
begin
Key := #0;
ShowMessage('Недопустимый элемент!');
end;
end;
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9': ;
else
begin
Key := #0;
ShowMessage('Недопустимый элемент!');
end;
end;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9': ;
else
begin
Key := #0;
ShowMessage('Недопустимый элемент!');
end;
end;
end;
end.