Hi all,
firstly I just want to say sorry for so many posts! This board is so dead that it makes me look bad posting so much lol.
Ok, so anyways, I had like ten edit boxes. Edit1, Edit2 ... Edit10
So I do a for count:
for count : 1 to 10
do
begin
if edit(count).text = ' ';
then edit(count).color := clRed;
But, the program wont let me do it, I get an error. It doesnt like the 'edit(count)' part. Is there any other way to check every edit box?
Thanks
Try this:
Code:for i:= 0 to (ComponentCount - 1) do begin if (Components[i] is TEdit) then begin if TEdit(Components[i]).text = '' then TEdit(Components[i]).color := clRed; end; end;
Umm...:
undeclared Identifier: 'ComponentCount'
undeclared identifier: 'Components'
Do I have to declare these under the variables?
Thanks
Identical components on Delphi form: components array
Components and ComponentCount are variables in your form.
So can you tell me what to write? Coz the link you gave me doesn't tell me what to put under variables.
Var
Components: ???;
ComponentCount: Integer;
Thanks
As long as you've inherited from TForm, they already exist.
But it doesnt work
Edit: What does inheritied mean? My form is called Form1
Can you paste your full code?
Here ya go:
Thanks!Code:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Label9: TLabel; g: TEdit; Button1: TButton; Label10: TLabel; Edit9: TEdit; Edit10: TEdit; Label11: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure Readonlycol; var Count: Integer; begin for count:= 0 to (Componentcount-1) do begin if (Components[count] is TEdit) then begin if Tedit(Components[count]).readonly = true then Tedit(Components[count]).color := clRed; end; end end; procedure TForm1.Button1Click(Sender: TObject); begin if (edit1.Text <> '') and (edit2.Text <> '') then begin edit3.ReadOnly:= true; edit4.ReadOnly:= true; end else begin edit3.ReadOnly:= false; edit4.ReadOnly:= false; end; unit1.Readonlycol; end; end.
Your procedure wasn't declared part of your form, so you didn't have access to your form's variables. Try this:
Code:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Label9: TLabel; g: TEdit; Button1: TButton; Label10: TLabel; Edit9: TEdit; Edit10: TEdit; Label11: TLabel; procedure Button1Click(Sender: TObject); procedure Readonlycol; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Readonlycol; var Count: Integer; begin for count:= 0 to (Componentcount-1) do begin if (Components[count] is TEdit) then begin if Tedit(Components[count]).readonly = true then Tedit(Components[count]).color := clRed; end; end end; procedure TForm1.Button1Click(Sender: TObject); begin if (edit1.Text <> '') and (edit2.Text <> '') then begin edit3.ReadOnly:= true; edit4.ReadOnly:= true; end else begin edit3.ReadOnly:= false; edit4.ReadOnly:= false; end; Readonlycol; end; end.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks