大家看一下。怎么在unit1中调用 unit2 中的代码
代码如下。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Image2: TImage;
Label3: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Button1: TButton;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Label3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.Color:=rgb(8,190,255); // 设置FORM1的颜色
{注意的几个问题: 1.Delphi程序中赋值符号为:=
2.颜色自定义的方法RGB(R,G,B)
3.Delphi里,每行语句必须以;号结尾}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage('测试程序 ^_^'); // 探出对话框显示内容
end;
procedure TForm1.Label3Click(Sender: TObject);
begin
form2.show; //显示form2
end;
end.
-----------------------------------------------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.