delphi中一个全局变量如何在两个form之间调用?那个form先调用这个变量?
我在form1中定义了全局变量N,点击form1中的btn1弹出form2.在form2中通过点击btn1对N赋值,再让N的值传递到form1中继续执行。新手上路,请高手...
我在form1中定义了全局变量N,点击form1中的btn1弹出form2.在form2中通过点击btn1对N赋值,再让N的值传递到form1中继续执行。新手上路,请高手指导~
下面是两个form的代码:
form1 :
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
hrc:HGLRC;
w,h:glFloat;
Sphere:GLUquadricObj;
public
{ Public declarations }
procedure Drawcs;
procedure MyDraw;
end;
var
Form1: TForm1;
transxfix,transyfix:double;
N:array[1..20,1..4] of glfloat;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.MyDraw;
begin
glPointSize(2.0);
glBegin(GL_QUADS);
glColor3f(0.0,0.0,0.0);
glVertex2f(N[1,1],N[1,2]);
glColor3f(1.0,0.0,0.0);
glVertex2f(N[2,1],N[2,2]);
glColor3f(0.0,0.0,1.0);
glVertex2f(N[3,1],N[3,2]);
glColor3f(0.0,1.0,0.0);
glVertex2f(N[4,1],N[4,2]);
glEnd();
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show;
end;
form2:
var
Form2: TForm2;
implementation
{$R *.dfm}uses unit1;
procedure TForm2.Button1Click(Sender: TObject);
begin
N[1,1]:=0.5;
N[1,2]:=0.5;
N[2,1]:=-0.5;
N[2,2]:=0.5;
N[3,1]:=-0.5;
N[3,2]:=-0.5;
N[4,1]:=0.5;
N[4,2]:=-0.5;
Form1.MyDraw;
Close;
end;
end.
想在form1中画个图,但有时候可以画,有时候画不出来,不知道什么原因。 展开
下面是两个form的代码:
form1 :
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
hrc:HGLRC;
w,h:glFloat;
Sphere:GLUquadricObj;
public
{ Public declarations }
procedure Drawcs;
procedure MyDraw;
end;
var
Form1: TForm1;
transxfix,transyfix:double;
N:array[1..20,1..4] of glfloat;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.MyDraw;
begin
glPointSize(2.0);
glBegin(GL_QUADS);
glColor3f(0.0,0.0,0.0);
glVertex2f(N[1,1],N[1,2]);
glColor3f(1.0,0.0,0.0);
glVertex2f(N[2,1],N[2,2]);
glColor3f(0.0,0.0,1.0);
glVertex2f(N[3,1],N[3,2]);
glColor3f(0.0,1.0,0.0);
glVertex2f(N[4,1],N[4,2]);
glEnd();
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show;
end;
form2:
var
Form2: TForm2;
implementation
{$R *.dfm}uses unit1;
procedure TForm2.Button1Click(Sender: TObject);
begin
N[1,1]:=0.5;
N[1,2]:=0.5;
N[2,1]:=-0.5;
N[2,2]:=0.5;
N[3,1]:=-0.5;
N[3,2]:=-0.5;
N[4,1]:=0.5;
N[4,2]:=-0.5;
Form1.MyDraw;
Close;
end;
end.
想在form1中画个图,但有时候可以画,有时候画不出来,不知道什么原因。 展开
1个回答
展开全部
调用方式没错误 错误的是你的其他地方吧
加个memo 代码里加调试信息写在memo里
显示坐标值
看看是你的画图程序出错 还是传递的坐标出错
我是估计是你的画图程序错了
加个memo 代码里加调试信息写在memo里
显示坐标值
看看是你的画图程序出错 还是传递的坐标出错
我是估计是你的画图程序错了
更多追问追答
追问
点击form2的bnt1后,是不是N就赋值完成了?下面的Form1.MyDraw是不是意思说接下执行form1中的.MyDraw过程?刚学delphi一个周,尝试在delphi中运用opengl 编程画图。
追答
对的 已经赋值完成
也的 是执行了MyDraw
其实你暂时不用画图 直接在memo里显示各坐标值就知道你的调用是没错的
错误的应该是你的画图程序 内部有啥异常 导致画图失败 画不出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询