Thread: For cycle

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    For cycle


    I have installed this component

    Code:
    http://stackoverflow.com/questions/6225787/slider-on-off-style-component-similar-to-ipad/12815846#12815846
    and in my form I have sereval sliders.
    How could I make a for cycle to set them all OFF?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    you could cycle through all the components on the form, and test to see if it's the component type you are looking for. If true, cast the component to the type, and turn it off.

    Code:
    procedure MyForm.TurnSlderOff;
    var
       I: Integer;
    begin
       for I := 0 to ComponentCount - 1 do//cycle through all components
       begin
          if Components[I] is TOnOffSwitch then//test for component type
             TOnOffSwitch(Components[I]).Off := False;//if it is the correct type, cast components[I] as the type and turn it off
       end;
    end;

IMN logo majestic logo threadwatch logo seochat tools logo