Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 24.05.2011, 20:56   #1
Dpo6oDyH
 
Регистрация: 17.05.2011
Сообщений: 8
По умолчанию Вопрос по RadioButton.

Я делаю тестирующую программу. В программе динамически создаются GroupBox и на них таким же образом создаются RadioButton.
Нужно сделать, чтобы при нажатии кнопки все RadioButton отжимались.
Вся программа:
unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm3 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;
i,k, qv, qt, bal: integer;
rbut, rbut2: array [1..10] of TRadioButton;
gbox: array [1..10] of TGroupBox;
f:textfile;

implementation

uses Unit1, Unit2;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
if MessageDlg('Вы уверены?', mtConfirmation, mbOkCancel,0)=mrOk then form1.close;
end;


procedure TForm3.FormCreate(Sender: TObject);
Var
St : String;
Begin
Qv := 10;
Qt := 1;
bal:=0;
Case Qt Of
1 :
For i:= 1 To Qv Do
Begin
GBox[i] := TGroupBox.Create(Form3);
GBox[i].Parent := Self;
GBox[i].Height := 70;
GBox[i].Width := 550;
GBox[i].Top := I*80-50;
GBox[i].Left := 10;

RBut[i]:=TRadioButton.Create(GBox[i]);
RBut[i].Parent := GBox[I];
RBut[i].Top := 15;
RBut[i].Left := 10;

RBut2[i] := TRadioButton.Create(GBox[i]);
RBut2[i].Parent := GBox[i];
RBut2[i].Top := 45;
RBut2[i].Left := 10;

AssignFile(f, 't1.txt');
Reset(f);
k := 1;
While (Not EoF(f)) And (k <= Qv) Do
Begin
ReadLn(f, St);
GBox[k].Caption := St;
k:=k+1;
End;
CloseFile(f);
RBut[i].Caption := 'Да';
RBut2[i].Caption := 'Нет';
End;

end;

End;

procedure TForm3.Button2Click(Sender: TObject);
begin
For i:= 1 To Qv Do
if RBut[i].Checked then bal:=bal+1;

ListBox1.Visible:=true;
if bal<=5 then
begin

ListBox1.Items.LoadFromFile('u1.txt ');
assignfile(f,'u1.txt');
reset(f);
while (not eof(f)) do
begin
readln(f);
k:=k+1;
end;
closefile(f);
end;

if bal>5 then
begin
ListBox1.Items.LoadFromFile('u2.txt ');
assignfile(f,'u2.txt');
reset(f);
while (not eof(f)) do
begin
readln(f);
k:=k+1;
end;
closefile(f);
end;
end;

procedure TForm3.Button3Click(Sender: TObject);
begin
//при нажатии этой кнопки должно обнуляться.
end;

procedure TForm3.Button4Click(Sender: TObject);
begin
end;

end.


Когда я не создавал динамически GroupBox, а клал его на форму работало это:
for i:=0 to (self.componentcount - 1) do
if self.components[i] is TRadioButton then
(self.components[i] as TRadioButton).Checked:=false;
Как это исправить чтобы работало в новой программе?
Заранее благодарен.
Dpo6oDyH вне форума Ответить с цитированием
Старый 24.05.2011, 23:42   #2
dmitriegorovih
Ещё не
Форумчанин
 
Аватар для dmitriegorovih
 
Регистрация: 04.01.2010
Сообщений: 517
По умолчанию

Код:
unit Unit3;

 interface

 uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

 type
 TForm3 = class(TForm)
 Button1: TButton;
 ListBox1: TListBox;
 Button2: TButton;
 Button3: TButton;
 Button4: TButton;
 procedure Button1Click(Sender: TObject);
 procedure FormCreate(Sender: TObject);
 procedure Button2Click(Sender: TObject);
 procedure Button3Click(Sender: TObject);
 procedure Button4Click(Sender: TObject);
 private
 { Private declarations }
 public
 { Public declarations }
 end;

 var
 Form3: TForm3;
 i,k, qv, qt, bal: integer;
 rbut, rbut2: array [1..10] of TRadioButton;
 gbox: array [1..10] of TGroupBox;
 f:textfile;

 implementation

 uses Unit1, Unit2;

 {$R *.dfm}

 procedure TForm3.Button1Click(Sender: TObject);
 begin
 if MessageDlg('Вы уверены?', mtConfirmation, mbOkCancel,0)=mrOk then form1.close;
 end;


 procedure TForm3.FormCreate(Sender: TObject);
 Var
 St : String;
 Begin
 Qv := 10;
 Qt := 1;
 bal:=0;
 Case Qt Of
 1 :
 For i:= 1 To Qv Do
 Begin
 GBox[i] := TGroupBox.Create(self);
 GBox[i].Parent := form3;
 GBox[i].Height := 70;
 GBox[i].Width := 550;
 GBox[i].Top := I*80-50;
 GBox[i].Left := 10;

 RBut[i]:=TRadioButton.Create(self);
 RBut[i].Parent := GBox[I];
 RBut[i].Top := 15;
 RBut[i].Left := 10;

 RBut2[i] := TRadioButton.Create(self);
 RBut2[i].Parent := GBox[i];
 RBut2[i].Top := 45;
 RBut2[i].Left := 10;

 AssignFile(f, 't1.txt');
 Reset(f);
 k := 1;
 While (Not EoF(f)) And (k <= Qv) Do
 Begin
 ReadLn(f, St);
 GBox[k].Caption := St;
 k:=k+1;
 End;
 CloseFile(f);
 RBut[i].Caption := 'Да';
 RBut2[i].Caption := 'Нет';
 End;

 end;

 End;

 procedure TForm3.Button2Click(Sender: TObject);
 begin
 For i:= 1 To Qv Do
 if RBut[i].Checked then bal:=bal+1;

 ListBox1.Visible:=true;
 if bal<=5 then
 begin

 ListBox1.Items.LoadFromFile('u1.txt ');
 assignfile(f,'u1.txt');
 reset(f);
 while (not eof(f)) do
 begin
 readln(f);
 k:=k+1;
 end;
 closefile(f);
 end;

 if bal>5 then
 begin
 ListBox1.Items.LoadFromFile('u2.txt ');
 assignfile(f,'u2.txt');
 reset(f);
 while (not eof(f)) do
 begin
 readln(f);
 k:=k+1;
 end;
 closefile(f);
 end;
 end;

 procedure TForm3.Button3Click(Sender: TObject);
 var
i:integer;
begin
for i:=0 to form3.ComponentCount-1 do begin
if form3.Components[i] is Tradiobutton then begin
TRadiobutton(form3.Components[i]).Checked:=false;
end;
end;
 //при нажатии этой кнопки должно обнуляться.
 end;

 procedure TForm3.Button4Click(Sender: TObject);
 begin
 end;

 end.
Воображение важнее, чем знания. (Albert Einstein)
dmitriegorovih вне форума Ответить с цитированием
Старый 25.05.2011, 10:00   #3
Dpo6oDyH
 
Регистрация: 17.05.2011
Сообщений: 8
По умолчанию

Спасибо! Всё работает
Dpo6oDyH вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
RadioButton 29_kapaT Компоненты Delphi 1 10.05.2010 03:30
radiobutton xxxn00bxxx Общие вопросы C/C++ 8 25.02.2010 08:06
radiobutton Bon'ka Компоненты Delphi 4 16.05.2009 21:56
RadioButton Pavelok Общие вопросы Delphi 3 14.05.2009 14:05
вопрос по RadioGroup и RadioButton Bayazet Общие вопросы Delphi 3 16.02.2009 17:50