
07.06.2011, 11:50
|
Начинающий
|
|
Регистрация: 04.02.2011
Адрес: Москва
Сообщения: 148
Версия Delphi: 7
Репутация: 133
|
|
Мне кажется удобнее на две процедуры разделить одна чистит все эдиты на одной форме, а другая на всех:
Код:
procedure AllInFormEditClear(aForm:TForm; aString:String);
var
i:Cardinal;
begin
for i:=0 to aForm.ComponentCount-1 do
if aForm.Components[i].ClassType = TLabeledEdit then
TLabeledEdit(aForm.Components[i]).Text := aString;
end;
procedure AllInAppEditClear(aString:String);
var i:Cardinal;
begin
for i:=0 to Application.ComponentCount-1 do
if Application.Components[i].ClassParent = TForm then
AllInFormEditClear(TForm(Application.Components[i]),aString);
end;
Код Первой Формы:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure AllInFormEditClear(aForm:TForm; aString:String); forward; // Объявление процедуры (очистить только на одной форме)
procedure AllInAppEditClear(aString:String); forward; // Объявление процедуры (очистить на всех формах)
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
//Очистка LabledEdit'ов
procedure AllInFormEditClear(aForm:TForm; aString:String);
var
i:Cardinal;
begin
for i:=0 to aForm.ComponentCount-1 do
if aForm.Components[i].ClassType = TLabeledEdit then
TLabeledEdit(aForm.Components[i]).Text := aString;
end;
procedure AllInAppEditClear(aString:String);
var i:Cardinal;
begin
for i:=0 to Application.ComponentCount-1 do
if Application.Components[i].ClassParent = TForm then
AllInFormEditClear(TForm(Application.Components[i]),aString);
end;
//Вызов процедуры очистки
procedure TForm1.Button1Click(Sender: TObject);
begin
AllInFormEditClear(Form1,'');
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Form2.Show;
end;
end.
Код второй формы:
Код:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
LabeledEdit4: TLabeledEdit;
LabeledEdit5: TLabeledEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1; //подключение юнита хранящего процедуру очистки
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
AllInFormEditClear(Form2,'СЛОВО'); //вызов процедуры
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
AllInAppEditClear('ALL EDITS CLEAR!')//вызов процедуры
end;
end.
|