请问,如何在程序运行期间加入控件,以及控件需要执行的事件代码?
提供一些这方面的思想,谢谢。

解决方案 »

  1.   

    var   E : TEdit ; 
     E := TEdit.Create(Self) ;
     E.Parent := self ;
      

  2.   

    呵呵,我举个例子:我要加一个时钟,然后给时钟的OnTime事件写一些代码,怎么做?
      

  3.   

    动态加入控件并响应事件:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, ADODB;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        procedure MyAfterConnect(Sender: TObject);
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.MyAfterConnect(Sender: TObject);
    begin
      ///
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      ado: TADOConnection;
    begin
      ado:=TADOConnection.Create(Self);
      with ado do
      begin
        parent:=form1;
        AfterConnect:=MyAfterConnect;
      end;
    end;end.
      

  4.   

    T.Create(this);
    T.Parent:=?;
    T.ShowWindow(SW_HIDE);
      

  5.   

    大家说让我赚:)  MyTimer1 : TTimer;
      MyTimer1:=TTimer.Create(self);
      with MyTimer1 do
        begin
          Enabled:=false;
          InterVal:=100;
          OnTimer:= OnMyTimer1;
          Enabled:= True;
        end;procedure TFrmmain.OnMyTimer1(Sender: TObject);
    begin
    end; 
      

  6.   

    请问:wjlsmail
    OnMyTimer1是动态创建的吗?
      

  7.   

    最重要的是PARENT属性一定要设的。事件可以这样,定义一个和这个事件相统一的方法,既参数一样,类型一样。
    然后,在你的代码中加入:MYCONTROL.ONEVEN := MYMOTH(自定义的方法);
      

  8.   

    OnTimer:= OnMyTimer1;OnMyTimer1 为响应事件 ,申明一下
      

  9.   

    TFrmmain 类中 申明 :
        procedure OnMyTimer1(Sender:TObject);
      

  10.   

    觉得可以用时钟; 将图片存在一个数组,每隔几秒换一个图片(给OnTimer 事件传入序号)
      

  11.   

    “procedure TFrmmain.OnMyTimer1(Sender: TObject);”这样的代码怎样在程序运行的时候加入。
      

  12.   

    to:wjlsmail
    你说的功能已经实现。现在是多组之间的速度关系,不是组内的。再想想
      

  13.   

    “也可以呀?”是指我的想法吗?但我不知道具体怎样动态添加控件。大家所说的我有点不理解:就是
      MyTimer1 : TTimer;(1)  MyTimer1:=TTimer.Create(self);
      with MyTimer1 do
        begin
          Enabled:=false;
          InterVal:=100;
          OnTimer:= OnMyTimer1;
          Enabled:= True;
        end;procedure TFrmmain.OnMyTimer1(Sender: TObject);(2)
    begin
    end; 
    (1)我不能事先声明该控件。
    (2)我不能事先声明onmytimer1过程。
    (苦笑)怎么做呢?
      

  14.   

    unit Unit11;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,ExtCtrls, StdCtrls;type
      TFrmmain = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure OnMyTimer1(Sender: TObject);
        procedure OnMyTimer2(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Frmmain: TFrmmain;
      MyTimer : Array of TTimer;implementation{$R *.dfm}procedure TFrmmain.FormCreate(Sender: TObject);
    begin
      SetLength(MyTimer,2) ;  MyTimer[0]:=TTimer.Create(self);
      with MyTimer[0] do
        begin
          Enabled:=false;
          InterVal:=1000;
          OnTimer:= OnMyTimer1;
          Enabled:= True;
        end;   MyTimer[1]:=TTimer.Create(self);
       with MyTimer[1] do
         begin
           Enabled:=false;
           InterVal:=1000;
           OnTimer:= OnMyTimer2;
           Enabled:= True;
         end;
    end;procedure TFrmmain.OnMyTimer1(Sender: TObject);
    var
      i : Integer ;
    begin
      I := 0 ;
      while not (I > 2) do
      begin
        Label1.Caption := IntToStr(i) ;
        Inc(i) ;
        Sleep(500) ;
      end ;end;procedure TFrmmain.OnMyTimer2(Sender: TObject);
    var
      i : Integer ;
    begin
      I := 0 ;
      while not (I > 10) do
      begin
        ShowMessage(IntToStr(i)) ;
        Inc(i) ;
        Sleep(100) ;
      end ;end;end.
      

  15.   

    质子:
        给我解释解释你的程序呗。我就是不明白
    procedure OnMyTimer2(Sender: TObject);怎么加上去的。
    2个3个好办,我要加20个呢?
      

  16.   

    一个一个写:) ,觉得你用那么多 Timer 来处理这个不是很好:) ,完全可以用数据库 ,一个就够了
      

  17.   

    为何一定要动态使用控件 ? 将所有图片存入数据库,加一个ID , 每 Timer.InterVal 间隔顺次将图片加载一次