delphi初始化问题
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
Genlength=30;Genwidth=80;
type
TForm1 = class(TForm)
Button1: TButton;
function CanTerminate(GenPoint:Tpoint;genLength,genWidth:Real):boolean;
procedure Button1Click(Sender: TObject);
Function ToPoint(GenPointFrom:TPoint;Genlength,Genwidth:Real;Isleft:Boolean):TPoint;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Tform1.CanTerminate(GenPoint:Tpoint;GenLength,GenWidth:Real):boolean;
begin
if (GenPoint.x<0) or (GenPoint.x>Self.ClientWidth)
or (GenPoint.y<0) or (GenPoint.y>self.ClientHeight)
or(GenLength<1) then
Result:=true
else
result:=False;
end;
Function Tform1.ToPoint(GenPointFrom:TPoint;Genlength,Genwidth:Real;Isleft:Boolean):TPoint;
begin
if Isleft then
begin
Result.x:=GenPointFrom.x+200;
Result.y:=GenPointFrom.y+200;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
GenPointto,GenPointFrom:TPoint; Genlength,Genwidth:Real;
begin
if CanTerminate(GenPointFrom,GenLength,GenWidth) then
begin
system.Exit;
end
else
begin
self.Canvas.Pen.Color:=clred;
self.canvas.MoveTo(GenPointFrom.x,GenPointFrom.y);
self.canvas.LineTo(GenPointto.x,GenPointto.y);
showmessage('GenPointFrom.x,GenPointFrom.y');
end;
end;
end.
错误 genlength、genwidth没有初始化 我不是很明白 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
Genlength=30;Genwidth=80;
type
TForm1 = class(TForm)
Button1: TButton;
function CanTerminate(GenPoint:Tpoint;genLength,genWidth:Real):boolean;
procedure Button1Click(Sender: TObject);
Function ToPoint(GenPointFrom:TPoint;Genlength,Genwidth:Real;Isleft:Boolean):TPoint;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Tform1.CanTerminate(GenPoint:Tpoint;GenLength,GenWidth:Real):boolean;
begin
if (GenPoint.x<0) or (GenPoint.x>Self.ClientWidth)
or (GenPoint.y<0) or (GenPoint.y>self.ClientHeight)
or(GenLength<1) then
Result:=true
else
result:=False;
end;
Function Tform1.ToPoint(GenPointFrom:TPoint;Genlength,Genwidth:Real;Isleft:Boolean):TPoint;
begin
if Isleft then
begin
Result.x:=GenPointFrom.x+200;
Result.y:=GenPointFrom.y+200;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
GenPointto,GenPointFrom:TPoint; Genlength,Genwidth:Real;
begin
if CanTerminate(GenPointFrom,GenLength,GenWidth) then
begin
system.Exit;
end
else
begin
self.Canvas.Pen.Color:=clred;
self.canvas.MoveTo(GenPointFrom.x,GenPointFrom.y);
self.canvas.LineTo(GenPointto.x,GenPointto.y);
showmessage('GenPointFrom.x,GenPointFrom.y');
end;
end;
end.
错误 genlength、genwidth没有初始化 我不是很明白 展开
展开全部
procedure TForm1.Button1Click(Sender: TObject);
var
GenPointto,GenPointFrom:TPoint; Genlength,Genwidth:Real; //这里定义
begin
if CanTerminate(GenPointFrom,GenLength,GenWidth) then //这里使用
你在使用GetLength, GetWidht变量的时候,没有对其预先赋值。
当然编绎器要提示了。
正常的使用方法是:
Var
GetLength, GetWidth: Real; //定义
begin
GetLength := 123; //赋值
GetWidth := 234; //赋值
if CanTerminate(GenPointFrom,GenLength,GenWidth) then //使用
var
GenPointto,GenPointFrom:TPoint; Genlength,Genwidth:Real; //这里定义
begin
if CanTerminate(GenPointFrom,GenLength,GenWidth) then //这里使用
你在使用GetLength, GetWidht变量的时候,没有对其预先赋值。
当然编绎器要提示了。
正常的使用方法是:
Var
GetLength, GetWidth: Real; //定义
begin
GetLength := 123; //赋值
GetWidth := 234; //赋值
if CanTerminate(GenPointFrom,GenLength,GenWidth) then //使用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询