![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#121
|
||||
|
||||
|
Код:
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin Button1.Enabled:=(Edit1.Text <> '') and (Edit2.Text <> '') and (Edit3.Text <> ''); end; |
|
#122
|
|||
|
|||
|
The Shadow спасибо 8))
|
|
#123
|
|||
|
|||
|
У меня еще один вопрос - можно ли поменять цвет формы на цвет, который ты хочешь - а не на те, которые имеются в Color?
|
|
#124
|
||||
|
||||
|
Цитата:
|
|
#125
|
|||
|
|||
|
Цитата:
Код:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, AppEvnts;
type
TForm2 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
Button3: TButton;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Label6: TLabel;
ApplicationEvents1: TApplicationEvents;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
n:integer;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
a:array [0..19] of real;
P:real;
i:integer;
c,d:real;
begin
n:=strtoint(edit3.Text);
stringgrid1.ColCount:=n;
randomize;
if n<=20 then
for i:=0 to n-1 do
begin
a[i]:=random(50--50+1)-50;
StringGrid1.Cells[i,0]:=FormatFloat('0.00',a[i]);
end
else ShowMessage('Количество элементов массива не удовлетворяет условию задачи');
P:=1;
c:=StrtoInt(Edit1.Text);
d:=StrtoInt(Edit2.Text);
if n<=20 then
for i:=0 to n-1 do
if (a[i]>0) and (a[i]>=c) and (a[i]<=d) then
P:=P*a[i];
Edit4.Text:= FormatFloat('0.00',P);
end;
procedure TForm2.Button2Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to n-1 do
StringGrid1.Cells[i,0]:=FormatFloat(' ',0);
Edit3.Clear;
Edit4.Clear;
Edit1.Clear;
Edit2.Clear;
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
Form1.Show;
Form2.Close;
end;
procedure TForm2.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
begin
Button1.Enabled:=(Edit1.Text <> '') and (Edit2.Text <> '') and (Edit3.Text <> '');
end;
end. |
|
#126
|
|||
|
|||
|
Массив описываешь как Array Of Type;
При проходе по массиву используешь Low(Массив) и High(Массив). Для установки длинный массива используешь SetLength(Массив,Новая_длинна). Все. В остальном динамический массив от статического ничем не отличается. |
|
#127
|
|||
|
|||
|
lmikle спасибо... буду так пробовать - просто двумерный массив перевел без проблем - а с одномерным проьблема небольшая.. ладно - разберусь думаю! Спасибо
Теперь у меня другая трабла - подскажите, плиз, как сделать что бы прога выдавала свое сообщение об ошибке когда в Edit вписываешь мусор всякий - например фф и т. д. или отрицательные числа- что бы только на положительные числа срабатывал? |
|
#128
|
|||
|
|||
|
пожалуйста!!!второй день ничего путного не выходит!!! двумерный динамический массив (nxn) задать генератором случайных чисел;запись во внешний фаил,чтение из файла,сортировка по возрастанию эл-тов
|
|
#129
|
|||
|
|||
|
Цитата:
Код:
case Key of '0'..'9':; else Key:=Chr(0);//сюда можно и сообщение об ошибке писать, но ИМХО это незачем end; |
|
#130
|
|||
|
|||
|
MegaPiha спасибо... прикольно - сообщение и правда не нужно
|
|
#131
|
|||
|
|||
|
А вот у меня еще вопросик - а можно как-то сделать, что бы при этой процедуре на Edit еще и BackSpace работал?
case Key of '0'..'9':; else Key:=Chr(0); end; |
|
#132
|
||||
|
||||
|
Chr(8); {или 7 точно не помню}
|
|
#133
|
|||
|
|||
|
Цитата:
Код:
case key of '0'..'9', #8:; else key :=chr(0); end; |
|
#134
|
|||
|
|||
|
MegaPiha, The Shadow спасибо 8)
|
|
#135
|
|||
|
|||
|
Цитата:
Можно сделать примерно так. Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
StringGrid3: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
nxn: array of array of integer;
n,m:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);//сохранение в файл
Var
s :TStringlist;
Str:String;
i,j : Integer;
begin
with TSaveDialog.Create(Owner) do
begin
DefaultExt:='.txt';
Filter:= 'Файлы проекта|*.txt';
if not Execute then exit;
s:=TStringList.Create;
s.Clear;
For i:=1 to n do
begin
Str := '' ;
For j:=1 to m do
str:=str+IntToStr(nxn[j,i])+' ';
s.Add(Str);
end;
S.SaveToFile(FileName);
end;
s.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);//чтение из файла
var
s :TStringlist;
i,j, posy, posx: Integer;
Str:String;
Begin
with TOpenDialog.Create(Owner) do
begin
DefaultExt:='.txt';
Filter:= 'файлы проекта|*.txt';
if not Execute then exit;
s:=TStringList.Create;
S.LoadFromFile(FileName);
For posy := 1 to S.Count do
begin
posx := 0;
Str := '';
For i := 1 to Length(S.Strings[posy-1]) do
begin
if S.Strings[posy-1][i] <> ' ' then
Str := Str + S.Strings[posy-1][i]
else
begin
StringGrid2.Cells[posx, posy-1] := Str;
Str := '';
inc(posx);
end;
end;
end;
S.Free;
end;
With StringGrid2 do begin
colCount:=posx;
RowCount:=posy;
For i:=0 to posx-1 do
ColWidths[i]:=Trunc(Width/posx);
end;
n:= StringGrid2.RowCount;
m:=StringGrid2.ColCount;
SetLength(nxn,m,n);
For i:=0 to n-2 do
For j:=0 to m-1 do
nxn[i,j]:=StrToInt(StringGrid2.Cells[i,j]);
end;
procedure TForm1.Button4Click(Sender: TObject);//заполнение массива
Var i, j:integer;
begin
if (Trim(Edit1.Text) <>'') and (Trim(Edit2.Text)<>'') then
begin
n:=StrToInt(Edit1.Text);
m:=StrToInt(Edit2.Text);
With StringGrid1 do begin
ColCount:=n;
RowCount:=m;
For i:=0 to n-1 do
ColWidths[i]:=Trunc(Width/n);
end;
SetLength(nxn,n+1,m+1);
Randomize;
For i:=1 to n do
For j:=1 to m do
begin
nxn[i,j]:=random(10);
StringGrid1.Cells[i-1,j-1]:=IntToStr(nxn[i,j]);
end;
end
else
ShowMessage('Не заполнена размерность массива!')
end;
procedure TForm1.Button3Click(Sender: TObject);//сортировка
var s,i,j,k:integer;
begin
for j:=0 to n-1 do
for k:=0 to m-2 do
for i:=0 to m-k-2 do
if nxn[i,j]>nxn[i+1,j] then
begin
S:=nxn[i,j];
nxn[i,j]:=nxn[i+1,j];
nxn[i+1,j]:=S;
end;
For i:=0 to n-2 do
For j:=0 to m-1 do
StringGrid3.Cells[i,j]:=IntToStr(nxn[i,j]);
With StringGrid3 do begin
colCount:=n-1;
RowCount:=m;
For i:=1 to colCount-1 do
ColWidths[i]:=Trunc(Width/colCount);
end;
end;
end. |