FindComponent1 (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use the function FindComponent to set the property PageControl of TabSheet, so it can be moved to Another PageControl in different a Form/Frame.

Code

unit Unit2;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs, Vcl.ComCtrls;

type
  TForm2 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure CreateForm;
begin

// Create instance of class TForm2 in Application

Form2 := TForm2.Create(Application);

// Set property PageControl

Form2.TabSheet1.PageControl := TPageControl(Application.FindComponent('Form1').FindComponent('PageControl1'));
Form2.TabSheet1.Show;

end;

procedure DestroyForm;
begin

// Validate the instance

if Assigned(Form2) then
  begin

  // Destroy the instance if assigned

  Form2.Destroy;

  end;

end;

initialization

// Call procedure CreateForm when the package is loaded
CreateForm;

finalization

// Call procedure DestroyForm when the package is unloaded
DestroyForm;

end.

Notes

  • If you are working with a Package Project and want to move TabSheet(Package) to another PageControl(VCL Forms Application/Another Package), you still can use the code above.

Uses