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.
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?
The controls are created at runtime like this:
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;
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.
I tried this but it returns nil:
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;
NEW: - this works
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
R开发者_JS百科esult := 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;
Thanks All
You made TopPanel
the owner of HorzontalRulerBox
(btw, it's HorIzontal :) ), so you need to search it with FindComponent
instead, but you'll have to first search TFormMain
for TopPanel
,and give TopPanel
a name in your code.
var
TP: TPanel;
rb: TRulerBox;
begin
TP := FindComponent('TopPanel') as TPanel;
if Assigned(TP) then
begin
rb := TP.FindComponent('HorzontalRulerBox` + IntToStr(whatever));
if Assigned(rb) then
// Work with ruler box
end;
end;
The function FindComponent
must be used by the Owner component.
The owner can be different than the parent, so be carefull.
In your example, the owner component is maybe the form, or the OfficePager.
Try replacing AdvOfficePager1.ActivePage
by self (to reference the form) or AdvOfficePager1
- I don't use these components so I'm not sure.
精彩评论