我的问题就是创建子窗口(不是MDI的)时,怎么才能不让它出现问题?一个主窗口:Form1;
一个子窗口:Form2;主窗口有一个Button1,按下它就执行:
var
  Form2:TForm2;
begin
  Form2:=TForm2.Create(Self);
  Form2.StartTime:=Time;//设置一个开始时间,当然StartTime早就定义好的,问题不在这里。
  Form2.Show;
end;  Fom2窗口有一个Timer1,它的事件处理如下:form2.Caption:=TimeToStr(Time-StartTime);
//以上就要以得到本窗口的运行时间了问题是,当我多按几次主窗口的Button1来创建多个Form2时,那几个Form2.Caption就会在1秒钟后全部变成一样的,这是怎么回事呢请各位帮帮我啊!!!

解决方案 »

  1.   

    just tryvar
    frm:array [0..n] of Tform2;
    begin
      frm[i]:=TForm2.Create(Self);
      frm[i].StartTime:=Time;
      frm[i].Show;
      inc(i);
    end;
      

  2.   

    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls;type
      TForm2 = class(TForm)
        Timer1: TTimer;
        Label1: TLabel;
        procedure Timer1Timer(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
         StartTime :TDateTime;
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.DFM}procedure TForm2.Timer1Timer(Sender: TObject);
    begin
        label1.Caption:=TimeToStr(now-StartTime);
    end;procedure TForm2.FormShow(Sender: TObject);
    begin
       if Timer1.Enabled=False then Timer1.Enabled :=True;
       StartTime :=Now;
    end;end.
    我没有发现你所说的结果,每个子窗口都有自己的运行时间
      

  3.   

    unit Unit1:::::::::::::::::::var
      Form1: TForm1;
    implementation
    uses Unit2;
    {$R *.DFM}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Form2:TForm2;
    begin
      Form2:=TForm2.Create(Self);
      Form2.starttime:=Time;
      Form2.Show;
    end;
    end.
    unit Unit2:::::::::::::::
    type
      TForm2 = class(TForm)
        Timer1: TTimer;
        procedure Timer1Timer(Sender: TObject);
      private
      public
        starttime:TDateTime;
      end;
    var
      Form2: TForm2;
    implementation
    {$R *.DFM}
    procedure TForm2.Timer1Timer(Sender: TObject);
    begin
      Caption:=TimeToStr(Time-StartTime);
    end;
    end.
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      i:integer;
    implementation
    uses unit2;
    {$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    var
    frm:array [0..5] of Tform2;
    begin
      frm[i]:=TForm2.Create(Application);
      frm[i].Show;
      inc(i);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      i:=0;end;end.
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls;type
      TForm2 = class(TForm)
        Timer1: TTimer;
        procedure Timer1Timer(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        starttime:Tdatetime;/////////////////////////定义私有变量
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation
    {$R *.DFM}procedure TForm2.Timer1Timer(Sender: TObject);
    begin
    Caption:=TimeToStr(time-StartTime);
    end;procedure TForm2.FormCreate(Sender: TObject);
    begin
    starttime:=time;
    end;end.
      

  5.   

    form2.Caption:=TimeToStr(Time-StartTime);=>Caption := TimeToStr(Time-StartTime);
      

  6.   

    var
    frm:Tform2;
    begin
      application.createform(Tform2,frm);
      frm.StartTime:=Time;
      frm.Show;end;
      

  7.   

    试试用 self.caption:= TimeToStr(Time-StartTime);
      

  8.   

    注意Timer1的interval属性呀,保证是你需要的间隔。
      

  9.   

    哈哈,原来是这样:)原来把它定义成 public的就行了,其实我已经是对的了,呵呵
    全部有分!!