Disabling TDBEdit lazarus / 8-Other ---------------------------------------------------------------------- ilniko · 2006-03-12 21:30 Hi all, i want to use something like this to disable TDBEdit controls stored in a PageControl, but it doesn't work:   for i := 0 to ControlCount - 1 do begin     if Components is TDBEdit then       (Components as TDBEdit).Enabled := bOk;   end; If I put the TDBEdit out of the PageControl, directly on the Form, it works without any problem. Iv'e tried putting also a "with PageControl1 do" before the "for", but nothing to do. How can I do? Nik ---------------------------------------------------------------------- JanH · 2006-03-13 16:39 try Code: [Select]   for i:=0 to Self.ComponentCount-1 do begin     c := Self.Components[i];     if( c is TDBEdit )and( c.Parent=TabSheet )then       c.Enabled := bOk;   end; ...but I did not tested this code ;-) ---------------------------------------------------------------------- ilniko · 2006-03-13 19:44 I've try but the compiler says: 'identifier idents no member "Parent"' Here's my code: procedure TFMain.EnableFields(bOk: boolean); var   i: integer;   c: TComponent; begin   for i := 0 to Self.ControlCount - 1 do begin     c := Self.Components;     if (c is TDBEdit) and (c.Parent = MyTabSheet) then       c.Enabled := bAbilita;   end; end; It seems that "Parent" is not recognized by a valid property of TComponent. Nik ---------------------------------------------------------------------- ilniko · 2006-03-13 21:04 I've found the solution, finally!! Here's the code: Code: [Select] procedure TFMain.EnableFields(bOk: boolean); var   i, p, t: integer;   c: TComponent;   ts: TTabSheet; begin   for i := 0 to FMain.ControlCount - 1 do begin     c := FMain.Controls[i];     if c is TPageControl then       for p := 0 to (c as TPageControl).PageCount - 1 do begin         ts := (c as TPageControl).Pages[p];         for t := 0 to ts.ControlCount -1 do begin           if ts.Controls[t].ClassNameIs('TDBEdit') then             ts.Controls[t].Enabled := bOk;           // put here any other Control to set Enable/Disable         end;       end;   end; end; The procedure loops into all the Form's controls, if it find a TPageControl, loops into any TPC's page, and in any page (TTabSheet) it loops into any TTS's control. Nik ---------------------------------------------------------------------- Marc · 2006-03-14 10:33 2 notes: *) If you have checked that Code: [Select]c is TPageControl then you can cast it directly by Code: [Select]TPageControl(c). This skips the internal check which Code: [Select](c as TPageControl) does. *) instead of using Code: [Select]if ts.Controls[t].ClassNameIs('TDBEdit') it is faster to use Code: [Select]if ts.Controls[t] is TDBEdit or of you only want TDBEdit and not derived components Code: [Select]if ts.Controls[t].ClassType = TDBEdit