Программы   Загрузка Партнерство   О компании Контакты  
 
                    
  Карта Сайта   
   





Поменять владельца компонента




unit ChOwn1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ButtonChange: TButton;
    ButtonList: TButton;
    ListBox1: TListBox;
    procedure ButtonChangeClick(Sender: TObject);
    procedure ButtonListClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses ChOwn2;

{$R *.DFM}

procedure TForm1.ButtonChangeClick(Sender: TObject);
var
  AComp: TComponent;
begin
  if Assigned (Button1) then
  begin
    // change parent
    Button1.Parent := Form2;
    // change owner
    AComp := Button1;
    RemoveComponent (AComp);
    Form2.InsertComponent (AComp);
  end;
end;

procedure TForm1.ButtonListClick(Sender: TObject);
var
 I: Integer;
begin
  ListBox1.Items.Clear;
  for I := 0 to ComponentCount - 1 do
    ListBox1.Items.Add (Components[I].Name);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage ('My owner is ' +
    ((Sender as TButton).Owner as TForm).Caption);
end;

end.


unit ChOwn2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm2 = class(TForm)
    ButtonList: TButton;
    ListBox1: TListBox;
    procedure ButtonListClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}


procedure TForm2.ButtonListClick(Sender: TObject);
var
 I: Integer;
begin
  ListBox1.Items.Clear;
  for I := 0 to ComponentCount - 1 do
    ListBox1.Items.Add (Components[I].Name);
end;

end.

Загрузить весь проект

           




Программы  |  Загрузка  |  Партнерство  |  О компании  |  Контакты

Copyright © LSD Software 2006 - 2011