1. 程式人生 > >Delphi Form1控制Form2 和文字顯示

Delphi Form1控制Form2 和文字顯示

 1. Form1 控制Form2

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses Unit2;           //新增這個語句就可以控制Form2
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
       Form1.Show;//Form1顯示
       Form2.Show;//Form2顯示
end;

end.

2 .edit 文字的的控制:

procedure TForm2.Button1Click(Sender: TObject);
begin
   Edit1.Text:= 'HELLO';
   showmessage(Edit1.Text);
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
    Edit1.Text:= '';
    showmessage(Edit1.Text);
   // Form2.Hide;
end;

end.