title: Can FindComponent Be Used To Find A Ruler on a PageControl Created at Runtime
body: <p>Actually I am using a ImageEN TRulerBox and a TAdvOfficePager (TMS) rather than a TPageControl; however, the TAdvOfficePager functions the same way as a TPageControl aside from property names.</p>
  
  <p>Two ImageEN TRulerBoxes and a TImageENView are added to a TAdvOfficePage at runtime.  The ruler orientation is set by the RulerDir property of the TRulerBox. Can FindComponent be used to find a HorzontalRulerBox and a VerticalRulerBox?</p>
  
  <p>The controls are created at runtime like this:</p>
  
  <pre><code>procedure TFormMain.AddPage;
  var
    AdvOfficePage: TAdvOfficePage;
    PixelPanel: TPanel;
  begin
    AdvOfficePage := TAdvOfficePage.Create( Self );
    AdvOfficePage.Parent := AdvOfficePager1;
    AdvOfficePager1.AddAdvPage( AdvOfficePage );
    AdvOfficePage.AdvOfficePager := AdvOfficePager1;
    AdvOfficePage.Caption := 'ImageEnView ' + IntToStr( AdvOfficePager1.AdvPageCount );
    AdvOfficePage.TabHint := 'ImageEnView ' + IntToStr( AdvOfficePager1.AdvPageCount );
    TopPanel := TPanel.Create( Self );
    TopPanel.Parent := AdvOfficePage;
    TopPanel.Height := 34;
    TopPanel.Align := alTop;
    TopPanel.Color := $00fcebdc;
    TopPanel.BorderStyle := bsNone;
    TopPanel.BevelOuter := bvNone;
    PixelPanel := TPanel.Create( TopPanel );
    PixelPanel.Parent := TopPanel;
    PixelPanel.Height := 40;
    PixelPanel.Width := 34;
    PixelPanel.Caption := 'Pix';
    PixelPanel.Align := alLeft;
    PixelPanel.Color := $00fdf3eb;
    PixelPanel.ParentBackground := False;
    PixelPanel.BorderStyle := bsNone;
    PixelPanel.BevelOuter := bvNone;
    HorzontalRulerBox := TRulerBox.Create( TopPanel );
    HorzontalRulerBox.Name := 'HorzontalRulerBox' + IntToStr( AdvOfficePager1.AdvPageCount );
    HorzontalRulerBox.Parent := TopPanel;
    HorzontalRulerBox.Align := alClient;
    HorzontalRulerBox.BackGround := $00fdf3eb;
    HorzontalRulerBox.RulerColor := $00fdf3eb;
    HorzontalRulerBox.GripBaseDim := 1;
    HorzontalRulerBox.RulerDir := rdHorizontal;
    LeftPanel := TPanel.Create( Self );
    LeftPanel.Parent := AdvOfficePage;
    LeftPanel.Width := 30;
    LeftPanel.Align := alLeft;
    LeftPanel.Color := $00fdf3eb;
    LeftPanel.BorderStyle := bsNone;
    LeftPanel.BevelOuter := bvNone;
    VerticalRulerBox := TRulerBox.Create( LeftPanel );
    VerticalRulerBox.Name := 'VerticalRulerBox' + IntToStr( AdvOfficePager1.AdvPageCount );
    VerticalRulerBox.Parent := LeftPanel;
    VerticalRulerBox.Align := alClient;
    VerticalRulerBox.BackGround := $00fdf3eb;
    VerticalRulerBox.GripBaseDim := 1;
    VerticalRulerBox.RulerDir := rdVertical;
    VerticalRulerBox.BackGround := $00fdf3eb;
    VerticalRulerBox.RulerColor := $00fdf3eb;
    ImageENView := TImageEnView.Create( Self );
    ImageENView.Parent := AdvOfficePage;
    ImageENView.Left := 0;
    ImageENView.Top := 0;
    ImageENView.Align := alClient;
    ImageENView.Center := True;
    ImageENView.Visible := True;
    ImageENView.BorderStyle := bsNone;
    ImageENView.MouseInteract := [ miSelect ];
    AdvOfficePager1.ActivePage := AdvOfficePage;
  end;
  </code></pre>
  
  <p>If FindComponent can not be used how do you get the handle to each of the two rulers at runtime?  I hope I have asked this question correctly and the information provided is clear.</p>
  
  <p>I tried this but it returns nil:</p>
  
  <pre><code>function TFormMain.GetHorzontalRuler: TRulerBox;
  // find horzontal TRulerBox component on a TPanel on a TAdvOfficePage
  var
    rb: TRulerBox;
  begin
    rb := AdvOfficePager1.ActivePage.FindComponent( 'HorzontalRulerBox' + IntToStr( AdvOfficePager1.ActivePageIndex ) )
      as TRulerBox;
    if Assigned( rb ) then
      Result := rb
    else
      Result := nil;
  end;
  </code></pre>
  
  <p><strong>NEW: - this works</strong></p>
  
  <pre><code>function TFormMain.GetHorzRuler: TRulerBox;
  var
    tp: TPanel;
    rb: TRulerBox;
  begin
    Result := nil;
    tp := FindComponent( 'TopPanel' + IntToStr( AdvOfficePager1.ActivePageIndex + 1 ) ) as TPanel;
    if Assigned( tp ) then
    begin
      rb := TRulerBox( tp.FindComponent( 'HorzontalRulerBox' + IntToStr( AdvOfficePager1.ActivePageIndex + 1 ) ) );
      if Assigned( rb ) then
        Result := rb;
    end
    else
      Result := nil;
  end;
  
  function TFormMain.GetVertRuler: TRulerBox;
  var
    tp: TPanel;
    rb: TRulerBox;
  begin
    Result := nil;
    tp := FindComponent( 'LeftPanel' + IntToStr( AdvOfficePager1.ActivePageIndex + 1 ) ) as TPanel;
    if Assigned( tp ) then
    begin
      rb := TRulerBox( tp.FindComponent( 'VerticalRulerBox' + IntToStr( AdvOfficePager1.ActivePageIndex + 1 ) ) );
      if Assigned( rb ) then
        Result := rb;
    end
    else
      Result := nil;
  end;
  </code></pre>
  
  <p>Thanks All</p>