注册 登录
编程论坛 Delphi论坛

关于两个窗口间的Memo数据传递的问题。

slc123456 发布于 2009-10-08 13:35, 1120 次点击
目前有两个窗体,每个窗体上都有一个memo,主窗体有个按钮,想在想按下按钮以后,第二个窗体的memo得到第一个窗体memo的值,但是用 form2.memo1.lines.add(form1.memo1.text)不可以。
另外两个窗体也互相引用了。
1 回复
#2
mohao1632009-10-10 14:23
我这样实现了,不知道能不能满足你的需要,我对这个也不是很了解
工程代码:
程序代码:

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.


单元Unit1代码:
程序代码:

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



单元Unit2代码:
程序代码:
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
1