关于两个窗口间的Memo数据传递的问题。
目前有两个窗体,每个窗体上都有一个memo,主窗体有个按钮,想在想按下按钮以后,第二个窗体的memo得到第一个窗体memo的值,但是用 form2.memo1.lines.add(form1.memo1.text)不可以。另外两个窗体也互相引用了。
program Project1; uses Forms, Unit1 in 'Unit1.pas' {Form1}, Unit2 in 'Unit2.pas' {Form2}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.CreateForm(TForm2, Form2); Application.Run; end.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,ShellAPI; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var str:string; begin str := '这里传给你'; memo1.Text := str; form2.Memo1.Text := form1.Memo1.Text; form2.Show; Form1.Hide; end; end.Unit1中定义了一个button和一个memo
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm2 = class(TForm) Memo1: TMemo; procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation uses Unit1; {$R *.dfm} procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction); begin Form1.Show; end; end.Unit2里面只定义了一个mome 工程实现了在单击form1的button的时候将memo1中的text传给form2中的memo1,并隐藏form1,在关闭form2的时候恢复form1