作图,救命啊,急 (10分)

  • 主题发起人 主题发起人 Richard-sun
  • 开始时间 开始时间
R

Richard-sun

Unregistered / Unconfirmed
GUEST, unregistred user!
本人用一个函数来画一个点:
procedure gj1(x,y:integer);
begin
form1.Image1.Canvas .pen.Width :=6;
form1.Image1.Canvas.MoveTo(x+y,x+y);
form1.Image1.Canvas.LineTo(x+y+1,x+y);
end;
但是,我在INTERFACE中声名,在implementation中定义了后
我调用函数GJ1(80,M),这里,M的取值来自一个EDIT的值,
为什么,我编译后,出错
[Error] Unit1.pas(43): Unsatisfied forward or external declaration: 'TForm1.gj1'
请各位高手指点
 
试一试这样:
...
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
...
private
{ Private declarations }
public
{ Public declarations }
procedure gj1(x,y:integer);
end;
...
implementation
...
procedure TForm1.gj1(x,y:integer);
// ~~~~~~~~~ 注意这里
begin
//后面的 Form1 就可以去掉了
Image1.Canvas.pen.Width := 6;
Image1.Canvas.MoveTo(x+y,x+y);
Image1.Canvas.LineTo(x+y+1,x+y);
end;
 
方便的话,多贴点代码出来,并同时附上编译错误提示
这样更便于解决问题。10 分钟后我就要睡觉了:-)快
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DB, Mask, DBCtrls, ADODB, DBTables, Grids,
DBGrids;

type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit4: TEdit;
Label4: TLabel;
Label5: TLabel;
ADOConnection1: TADOConnection;
Label6: TLabel;
Button2: TButton;
Edit5: TEdit;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
Label7: TLabel;
DBGrid1: TDBGrid;
Edit6: TEdit;
Button3: TButton;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Label8: TLabel;
Memo1: TMemo;
DBNavigator1: TDBNavigator;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure tform1.gj1(x,y:integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var x,y,z,a,b,c,d,m:integer;
begin
try
image1.canvas.fillrect(Rect(0,0,1000,1000)); //.Pen.color:=clmenu;
image1.Canvas.pen.Width :=2;
image1.canvas.Refresh;
x:=strtoint(edit2.text)div 5+80;
y:=strtoint(edit1.Text)div 5+80;
z:=strtoint(edit3.text)div 5;
c:=z+x;
d:=z+y;
a:=80-z;
b:=80-z;
m:=strtoint(edit4.Text )div 5;
image1.canvas.pen.Color :=clblack;
image1.Canvas .rectangle(a,b,c,d);
image1.canvas.rectangle(80,80,x,y);
gj1(80,m);
except
application.MessageBox('请输入有效的数值','系统提示');
end;
end;


procedure gj1(x,y:integer);
begin
form1.Image1.Canvas .pen.Width :=6;
form1.Image1.Canvas.MoveTo(x+y,x+y);
form1.Image1.Canvas.LineTo(x+y+1,x+y);
end;
 
原来的错误就是
Error] Unit1.pas(43): Unsatisfied forward or external declaration: 'TForm1.gj1'
 
错了,上面(interface中)的声明部分中不要 TForm1.
即改为 procedure gj1(x,y:integer);
 
你照着 procedure Button1Click(Sender: TObject); 画(葫芦)不就行了:-)
 
那我再试试
 
接受答案了.
 

Similar threads

后退
顶部