Form1里有一个button1,Form2里有一个Edit1,
现想按下Form1里的button1后,Form2里的Edit1的Text变为‘hello’,
请问button1的触发事件怎么写?
我用了Form2.edit1.text:='hello';
好像不行啊,
谢谢

解决方案 »

  1.   

    接分!!
    可以的,只要你在form1的implementation 下写:uses unit2;就可以了。
      

  2.   

    uses unit2  //form2所在单元
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Form2.Edit1.Text :='hello';
    form2.Show;
    end;
      

  3.   

    我试过了 好用呀 你的unit1 user Unit2了吗?
      

  4.   

    简单一点的方法就是写一个公共参数进行传递,比如说:
    var strPost:string;
    button1click
    begin
      strPost:=1;
    end;
    form2中
    if strPost=1 then
     edit1.text:='hello!'
      

  5.   

    1、你只要在implementation中直接引用form2的单元文件就可以啦!uses unit1
    2、若使用菜单项中的file项中的use unit项进行引用。
     经过这样以后就可以直接使用你的方法进行赋值了!
      

  6.   

    在DELPHI的程序开发中,用户登陆窗口的用处非常的大,下面的代码是这类效果的简单实现。
      首先new一个新的工程,然后再新建一个是form,进入project菜单,单击其中的option菜单后进入,使form2成为不自动创建(方法为:在auto-create forms中选中form2,然后双击即可,单击ok按钮)。 
      此程序的原理是通过在密码窗体(运行时首先显示此窗体)输入的密码文本是否和主窗体中的edit中的文本一样,如果一样就进入程序,否则退出程序。
      在form1,form2中各加一个eidt控件,然后在form2中加入一个button控件。
      程序源码如下:
    工程文件:
    program Project1;uses
    Forms,
    Unit1 in 'Unit1.pas' {Form1},
    Unit2 in 'Unit2.pas' {Form2};{$R *.RES}begin
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    form2:=tform2.create(application);
    form2.showmodal;
    if (text1<>form1.edit1.text) then
    begin
    application.Terminate;
    end;
    Application.Run;
    end.单元1文件
    unit Unit1;interfaceuses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls;type
    TForm1 = class(TForm)
    Edit1: TEdit;
    private
    { Private declarations }
    public
    { Public declarations }
    end;var
    Form1: TForm1;implementation{$R *.DFM}end.
    单元2文件
    unit Unit2;interfaceuses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls;type
    TForm2 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;var
    Form2: TForm2;
    text1:string;
    implementation{$R *.DFM}procedure TForm2.Button1Click(Sender: TObject);
    begin
    text1:=form2.edit1.text;
    form2.close;
    end;end.