|
Вопрос # 4 625/ вопрос открыт / |
|
Доброго времени суток, уважаемые эксперты!
Есть две формы. Как сделать так чтобы при нажатии кнопки на форме 2 она закрывалась и открывалась 1 форма и становилась кнопка на 1 форме активной? Кнопка неактивна когда заходишь сначала на 1 форму.
Приложение: Переключить в обычный режим-
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, FMTBcd, DBXpress, DB, SqlExpr, Grids, DBGrids, StdCtrls,
- ExtCtrls, DBCtrls, DBClient, Provider, SimpleDS, Menus;
-
- type
- TForm1 = class(TForm)
- SQLConnection1: TSQLConnection;
- Q1: TSQLQuery;
- Button1: TButton;
- StringGrid1: TStringGrid;
- procedure Button1Click(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- procedure StringGrid1DblClick(Sender: TObject);
- procedure Button2Click(Sender: TObject);
-
-
-
-
-
-
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses Unit2, Unit3, Unit4;
-
- {$R *.dfm}
-
-
-
-
-
-
-
-
-
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- Form4:= TForm4.Create(Application);
- Form4.Caption:= 'Íîâàÿ
àêöèÿ';
- form4.Show;
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- var i:integer;
- begin
- try
- Q1.Open;
- except
- on e: exception do showmessage(e.Message);
- end;
- stringgrid1.Visible:=false;
- i:=1;
-
-
-
-
- while not Q1.Eof do
- begin
-
-
- StringGrid1.Cells[0,0]:= 'Àêöèÿ';
- StringGrid1.Cells[1,0]:=
'Îïèñàíèå';
- StringGrid1.Cells[2,0]:= 'Äàòà
íà÷àëà';
- StringGrid1.Cells[3,0]:= 'Äàòà
îêîí÷àíèÿ';
- StringGrid1.Cells[4,0]:=
'Êîëè÷åñòâî
áîíóñîâ';
- StringGrid1.Cells[5,0]:=
'Àêòèâíûå';
- StringGrid1.Cells[6,0]:=
'Ïðàçäíè÷íûå';
-
-
-
- stringgrid1.Cells[0,i]:=q1.Fields[0].AsString;
- stringgrid1.Cells[1,i]:=q1.Fields[1].AsString;
- stringgrid1.Cells[2,i]:=q1.Fields[2].AsString;
- stringgrid1.Cells[3,i]:=q1.Fields[3].AsString;
- stringgrid1.Cells[4,i]:=q1.Fields[4].AsString;
- stringgrid1.Cells[5,i]:=q1.Fields[5].AsString;
- stringgrid1.Cells[6,i]:=q1.Fields[6].AsString;
-
- q1.Next;
- inc(i);
- stringgrid1.RowCount:=i+1;
- end;
- stringgrid1.Visible:=true;
- if q1.Active then q1.Close;
-
- end;
-
-
-
-
-
- procedure TForm1.StringGrid1DblClick(Sender: TObject);
- begin
- Form3:= TForm3.Create(Application);
- Form3.Caption:= 'Íîâàÿ
àêöèÿ';
- form3.Show;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- Form2:= TForm2.Create(Application);
- Form2.Caption:= 'Âûáîð';
- form2.Show;
- end;
-
-
-
- end.
-
-
-
- unit Unit2;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Grids, DBGrids, DBXpress, FMTBcd, DBClient, SimpleDS, DB,
- SqlExpr, ExtCtrls, DBCtrls, StdCtrls;
-
- type
- TForm2 = class(TForm)
- SQLConnection2: TSQLConnection;
- Q2: TSQLQuery;
- StringGrid2: TStringGrid;
- ComboBox1: TComboBox;
- Label1: TLabel;
- Label3: TLabel;
- ComboBox3: TComboBox;
- Label4: TLabel;
- Edit1: TEdit;
- Button1: TButton;
- RadioGroup1: TRadioGroup;
- Button2: TButton;
- procedure FormActivate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button2Click(Sender: TObject);
-
-
-
-
-
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form2: TForm2;
-
- implementation
-
- uses Unit4;
-
- {$R *.dfm}
-
-
- procedure TForm2.FormActivate(Sender: TObject);
- var q:integer;
-
- begin
- try
- Q2.Open;
- except
- on e:exception do showmessage(e.Message)
- end;
- stringgrid2.Visible:=false;
- stringgrid2.RowCount:=2;
- q:=1;
-
- while not Q2.Eof do
- begin
- StringGrid2.Cells[0,0]:= 'Ôàìèëèÿ';
- StringGrid2.Cells[1,0]:= 'Èìÿ';
- StringGrid2.Cells[2,0]:=
'Îò÷åñòâî';
- StringGrid2.Cells[3,0]:=
'Äîìàøíèé
òåëåôîí';
- StringGrid2.Cells[4,0]:= 'Ðàáî÷èé
òåëåôîí';
- StringGrid2.Cells[5,0]:=
'Ìîáèëüíûé
òåëåôîí';
- StringGrid2.Cells[6,0]:= 'Ïî÷òà';
- StringGrid2.Cells[7,0]:= 'Äàòà
ðîæäåíèÿ';
- StringGrid2.Cells[8,0]:=
'Ñåìåéíîå
ïîëîæåíèå';
- StringGrid2.Cells[9,0]:= 'Ñôåðà
äåÿòåëüíîñòè';
- StringGrid2.Cells[10,0]:= 'Ïîë';
-
- stringgrid2.Cells[0,q]:=Q2.fields[0].AsString;
- stringgrid2.Cells[1,q]:=Q2.fields[1].AsString;
- stringgrid2.Cells[2,q]:=Q2.fields[2].AsString;
- stringgrid2.Cells[3,q]:=Q2.fields[3].AsString;
- stringgrid2.Cells[4,q]:=Q2.fields[4].AsString;
- stringgrid2.Cells[5,q]:=Q2.fields[5].AsString;
- stringgrid2.Cells[6,q]:=Q2.fields[6].AsString;
- stringgrid2.Cells[7,q]:=Q2.fields[7].AsString;
- stringgrid2.Cells[8,q]:=Q2.fields[8].AsString;
- stringgrid2.Cells[9,q]:=Q2.fields[9].AsString;
- stringgrid2.Cells[10,q]:=Q2.fields[10].AsString;
-
-
- Q2.Next;
- inc(q);
- stringgrid2.RowCount:=q+2;
- end;
- stringgrid2.Visible:=true;
- if Q2.Active then Q2.Close;
-
- combobox1.Clear;
- Form2.Q2.SQL.Text:='select DISTINCT family_status from owner';
- Form2.Q2.Open;
- if Form2.Q2.Active then
- begin
- Form2.Q2.First;
- while not q2.Eof do
- BEGIN
- Form2.ComboBox1.Items.Add(Form2.Q2.FieldByName('family_status').AsString);
- Form2.Q2.Next;
- END;
- q2.Close;
- END;
-
-
- combobox3.Clear;
- Form2.Q2.SQL.Text:='select DISTINCT typeorg from owner';
- Form2.Q2.Open;
- if Form2.Q2.Active then
- begin
- Form2.Q2.First;
- while not q2.Eof do
- BEGIN
- Form2.ComboBox3.Items.Add(Form2.Q2.FieldByName('typeorg').AsString);
- Form2.Q2.Next;
- END;
- q2.Close;
- end;
-
-
-
-
-
-
- end;
-
-
-
-
-
- procedure TForm2.Button1Click(Sender: TObject);
- begin
- q2.SQL.Text:='select * from owner where DateDiff(year,date_of_birth,GetDate())='+Edit1.Text+' and
family_status ='+char(39)+Combobox1.Text+char(39)+' and TypeOrg =
'+char(39)+Combobox3.Text+char(39)+' and sex='+inttostr(RadioGroup1.Itemindex);
- q2.Open;
- form2.FormActivate(Sender);
- q2.Close;
- end;
-
-
-
- procedure TForm2.FormCreate(Sender: TObject);
- var
- x, y, w: integer;
- s: string;
- MaxWidth: integer;
- begin
- with StringGrid2 do
- ClientHeight := DefaultRowHeight * RowCount + 5;
- randomize;
- with StringGrid2 do begin
- for y := 0 to RowCount - 1 do
- for x := 0 to ColCount - 1 do begin
- s := '';
- for w := 0 to random(20) do
- s := s + chr(ord('a') + random(26));
- Cells[x,y] := s;
- end;
-
- Canvas.Font := Font;
- for x := 0 to ColCount - 1 do begin
- MaxWidth := 0;
- for y := 0 to RowCount - 1 do begin
- w := Canvas.TextWidth(Cells[x,y]);
- if w > MaxWidth then MaxWidth := w;
- end;
- ColWidths[x] := MaxWidth + 5;
-
- end;
- end;
- end;
-
-
-
- procedure TForm2.Button2Click(Sender: TObject);
- begin
- Q2.SQL.Text:='use bonus_dbTest go declare @counts int select @counts = count(distinct field_id) from
act_new where active=1 if @counts<4 then begin insert into act_new() values() alter table
dbo.spiski add act_4 bit not null constraint df_spiski_act_4 default 0';
- Form4:= TForm4.Create(Application);
- Form4.Caption:= 'Íîâàÿ
àêöèÿ';
- Form4.Enabled:=true;
- form4.Show;
- q2.Close;
- end;
-
- end.
 |
Вопрос задал: slai (статус: Посетитель)
Вопрос отправлен: 1 октября 2010, 07:53
Состояние вопроса: открыт, ответов: 1.
|
Ответ #1. Отвечает эксперт: Тов. Женька
Здравствуйте, slai!
Например, так:
procedure TForm1.PButtonEx1Click(Sender: TObject);
begin
Hide; // скрываем нашу форму 1
try
with TForm2.Create(nil) do
begin
ActiveControl := Button2;
Showmodal;
end;
finally
Free;
end;
end;
 |
Ответ отправил: Тов. Женька (статус: 3-ий класс)
Время отправки: 1 октября 2010, 08:47
Оценка за ответ: 5
|
Мини-форум вопроса
Всего сообщений: 1; последнее сообщение — 1 октября 2010, 08:55; участников в обсуждении: 1.
|
Тов. Женька (статус: 3-ий класс), 1 октября 2010, 08:55 [#1]:
А не, ошибку допустил.
...
with TForm2.Create(nil) do
begin
try
ActiveControl := Button2;
Showmodal;
finally
Free;
end;
end;
...
|
Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.
|