Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

How to set TEdit properties at runtime?

Hi,

I'm running Delphi 7 on WinXP Pro SP3.  I have a series of 20 edit boxes Edit1 to Edit20.  Based on a definable criteria, how do I change the properties of only certain TEdit fields?

For example, for "Criteria 1", I want TEdit fields 3, 4, 5 & 12 Color property set to clMediumGray.  Edit fields 1, 2, 6-11, 13-20 remain unchanged.

Code below loops through TEdit fields, but I don't know how to further identify a specific TEdit(x) where x is 1, 2,..., 20.

Is this possible?  If so how do I do it?
procedure SetCriteria_1;
begin
var
  I: Integer;
begin
  with Form1 do
  for I := 0 to Form1.ComponentCount - 1 do
    begin
      if Form1.Components[I] is TEdit then
        with Form1.Components[I] as TEdit do
        begin
          << I want to execute this code for only certain TEdit(x) fields.  How do I code selection criteria to identify only specific Edit(x) fields and do the assignment?
 >>
            Color   := clMediumGray;
            Enabled := False;
        end
    end;

end;

Open in new window

0
IT79637
Asked:
IT79637
1 Solution
 
rfwoolfCommented:
How about the tag property?
0
 
bxxxnCommented:
Why Don't you just put a condition, this way if you like to change Edit1, Edit3 and Edit5 then

procedure SetCriteria_1;
begin
var
  I: Integer;
begin
  with Form1 do
  for I := 0 to Form1.ComponentCount - 1 do
    begin
      if Form1.Components[I] is TEdit then
        with Form1.Components[I] as TEdit do
        begin
            if ((I=1) or (I=3) or (I=5)) then begin
              Color   := clMediumGray;
              Enabled := False;
          end;
        end
    end;

end;

//Regards B.
0
 
MerijnBSr. Software EngineerCommented:
a little bit nicer:

procedure SetCriteria_1;
begin
var
  I: Integer;
begin
  with Form1 do
  for I := 0 to Form1.ComponentCount - 1 do
    begin
      if Form1.Components[I] is TEdit then
        with Form1.Components[I] as TEdit do
        begin
            if (I in [1, 3, 5]) then begin
              Color   := clMediumGray;
              Enabled := False;
          end;
        end
    end;

end;

Open in new window

0
 
IT79637Author Commented:
Thanks!  Makes sense to me.  I.m just not a proficient Delphi coder.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now