Lista wszystkich kontrolek danej TFrame

0

Cześć

Mam aplikację zbudowaną tak że jest jedna forma, i kazda funkcja tworzy TFrame w ktorej są rózne panele, kontrolki itp...
Proszę podpowiedzcie co robie zle lub podpowiedzcie łatwiejsze rozwiązanie. ja utknąłem.
Delphi 2007
Potrzebuję się dostać do wszystkich kontrolek na danym Frame.

Nic nie daje :

 
with FormMain.CurrentFrame do
 begin
    for i1 := 0 to ControlCount - 1 do ...

bo wtedy dostaję się tylko do kontrolek pierwszego rzędu (2 panele, label i obrazek) a to nic nie daje, bo potrzebuje też podległe.

wiec zrobiłem funkcję która rekurencyjnie powinna dodawać kontrolki do listy

 
procedure XXX.PopulateControls(aParent: TWincontrol);
var
 i1 : Integer;
 ctrl : TControl;
begin
  ControlsList.Add(aParent);
  for i1 := 0 to aParent.ControlCount - 1 do
  begin
    ctrl := aParent.Controls[i1];
    if ctrl is TWincontrol then
      PopulateControls(TWinControl(ctrl))
    else
      ControlsList.Add(TWinControl(ctrl));
  end;
end;

a tu definicja listy

 
unit uControls;

interface
  uses Classes, Controls, uBaseObject;

  Type
    TControlsList = class(TList)
    private
      procedure PutCtrl(Index: integer; Value: TWinControl);
      function GetCtrl(Index: integer): TWinControl;
    public
        constructor Create; virtual;
        destructor Destroy; override;
        function Add(Item : TWinControl) : Integer;
        function IndexOf(AItem: Pointer): integer; overload;

        property Items[Index: Integer]: TWinControlread GetCtrl write PutCtrl; default;
    end;
implementation

{ TControlsList }

procedure TControlsList.PutCtrl(Index: integer; Value: TWinControl);
begin
  inherited Items[Index] := Value;
end;

function TControlsList.GetCtrl(Index: integer): TWinControl;
begin
  Result := TControl(inherited Items[Index]);
end;
constructor TControlsList.Create;
begin
  inherited Create;
end;

destructor TControlsList.Destroy;
begin

  inherited Destroy;;
end;

function TControlsList.Add(Item: TWinControl): Integer;
begin
  Result := inherited Add(Item);
end;


function TControlsList.IndexOf(AItem: Pointer): integer;
begin
  Result := 0;
  while (Result < Count) and (Pointer(Items[Result]) <> AItem) do
    Inc(Result);
  if Result = Count then
    Result := -1;
end;

i przy wywołaniu (testowym) lista jest pusta

 
  if Assigned(ControlsList) then FreeAndNil(ControlsList);
  ControlsList := TControlsList.Create();

  PopulateControls(FormMain.CurrentFrame);
  for i1 := 0 to ControlsList.Count - 1 do
    ShowMessage(ControlsList.Items[i1].Name);

  ControlsList.Free;
0

Proszę podpowiedzcie co robie zle lub podpowiedzcie łatwiejsze rozwiązanie. ja utknąłem.

Robisz źle: NIE UŻYWASZ DEBUGGERA.
Łatwiejsze rozwiązanie: TObjectList

0
  1. Może wyjaśnij co próbujesz osiągnąć czyli po kiego? Pomijasz nie WinControl, potem te nie WinControl konwertujesz na WinControl zaś odbierasz jako WinControlRead?
  2. czy nie prościej przelecieć raz zaś po Components[]?
0

no fajnie, poczytam, ale to nie rozwiązuje problemu.

Jakbyś umiał użyć debuggera z komponentem TBrain to uwierz mi, rozwiązałoby problem.

1 użytkowników online, w tym zalogowanych: 0, gości: 1