求教:有关于function和procedure的问题(100分)

  • 主题发起人 主题发起人 ywan
  • 开始时间 开始时间
Y

ywan

Unregistered / Unconfirmed
GUEST, unregistred user!
各位新年好!小弟在使用自定义function和procedure时出现以下错误:
Unsatisfied forward or external declaration :"TdataModule5.check_oder"
Unsatisfied forward or external declaration :"TdataModule5.get_id"
Unsatisfied forward or external declaration :"TdataModule5.add_data"

具体程序如下

unit Unit5;

interface

uses
SysUtils, Classes, DB, ADODB;


type
TDataModule5 = class(TDataModule)
ADOConnection1: TADOConnection;
Oder_ADOQuery: TADOQuery;
Ins_ADOQuery: TADOQuery;
Out_ADOQuery: TADOQuery;
Save_ADOQuery: TADOQuery;
Oder_DataSource: TDataSource;
Ins_DataSource: TDataSource;
Out_DataSource: TDataSource;
Save_DataSource: TDataSource;

function check_oder (var get_query :Tadoquery
get_name:string):boolean;//这里出错
function get_id (var get_query1:Tadoquery
get_names:string ): integer;//这里出错

procedure add_data( var add_query add_name,add_table:string
add_quanlity :integer);;//这里出错



private
{ Private declarations }
public

{ Public declarations }

end;
var
DataModule5: TDataModule5;

implementation


{$R *.dfm}


function check_oder (var get_query:tadoquery
get_name:string):boolean;
var
sql_text:string
begin
sql_text:='select * from oder ';
sql_text:=sql_text + 'where name = '
sql_text:=sql_text + get_name
with get_query do
begin
close;
sql.clear;
sql.add(sql_text);
open;
if not eof then
result:=true
else
result:=false;
end;
end;

function get_id(var get_query1:tadoquery
get_name:string):integer;
var
sql_text1 :string;
begin
sql_text1:='select * from oder';
sql_text1:=sql_text1 + ' where name = ';
sql_text1:=sql_text1 + ' get_name ';
with get_query1 do
begin
close;
sql.clear;
sql.add(sql_text1);
open;
result:=fieldbyname('ID').asinteger;
end;
end;
procedure add_data ( var add_query2 :Tadoquery add_table:string
add_id,add_quanlity :integer);
var
sql_text2:string;
begin
sql_text2:='insert into '+ add_table;
sql_text2:=sql_text2 + ' ID, quanlity, date ';
sql_text2:=sql_text2 + 'value (:id, :quanlity :date )';
with add_query2 do
begin
close;
sql.clear;
sql.add(sql_text2);
parameters.parambyname('id').value:=add_id;
parameters.parambyname('quanlity').value:=add_quanlity;
parameters.parambyname('date').value:=date;
open;
end;
end;






end.
 
都改成类似于下面的
function TDataModule5.check_oder (var get_query :Tadoquery
get_name:string):boolean;//
 
实现部分
function check_oder (var get_query:tadoquery
get_name:string):boolean;
改成
function TdataModule5.check_oder (var get_query:tadoquery
get_name:string):boolean;
其他相同的都需要加上TdataModule5
 
可以把函数的声明部分去掉
procedure写在private中
 
同意楼上的楼上
 
把函数的声明放这里:
var
DataModule5: TDataModule5;
//声明
function check_oder (var get_query :Tadoquery
get_name:string):boolean;//这里出错
function get_id (var get_query1:Tadoquery
get_names:string ): integer;//这里出错
procedure add_data( var add_query add_name,add_table:string
add_quanlity :integer);;//这里出错
 
放在Private下
 
这样就行啦:

unit Unit5;
interface
uses
SysUtils, Classes, DB, ADODB;
type
TDataModule5 = class(TDataModule)
ADOConnection1: TADOConnection;
Oder_ADOQuery: TADOQuery;
Ins_ADOQuery: TADOQuery;
Out_ADOQuery: TADOQuery;
Save_ADOQuery: TADOQuery;
Oder_DataSource: TDataSource;
Ins_DataSource: TDataSource;
Out_DataSource: TDataSource;
Save_DataSource: TDataSource;

function check_oder (var get_query :Tadoquery
get_name:string):boolean;//这里出错
function get_id (var get_query1:Tadoquery
get_names:string ): integer;//这里出错

procedure add_data( var add_query add_name,add_table:string
add_quanlity :integer);;//这里出错



private
{ Private declarations }
public

{ Public declarations }

end;
var
DataModule5: TDataModule5;

implementation


{$R *.dfm}


function TDataModule5.check_oder (var get_query:tadoquery
get_name:string):boolean;
var
sql_text:string
begin
sql_text:='select * from oder ';
sql_text:=sql_text + 'where name = '
sql_text:=sql_text + get_name
with get_query do
begin
close;
sql.clear;
sql.add(sql_text);
open;
if not eof then
result:=true
else
result:=false;
end;
end;

function TDataModule5.get_id(var get_query1:tadoquery
get_name:string):integer;
var
sql_text1 :string;
begin
sql_text1:='select * from oder';
sql_text1:=sql_text1 + ' where name = ';
sql_text1:=sql_text1 + ' get_name ';
with get_query1 do
begin
close;
sql.clear;
sql.add(sql_text1);
open;
result:=fieldbyname('ID').asinteger;
end;
end;
procedure TDataModule5.add_data ( var add_query2 :Tadoquery add_table:string
add_id,add_quanlity :integer);
var
sql_text2:string;
begin
sql_text2:='insert into '+ add_table;
sql_text2:=sql_text2 + ' ID, quanlity, date ';
sql_text2:=sql_text2 + 'value (:id, :quanlity :date )';
with add_query2 do
begin
close;
sql.clear;
sql.add(sql_text2);
parameters.parambyname('id').value:=add_id;
parameters.parambyname('quanlity').value:=add_quanlity;
parameters.parambyname('date').value:=date;
open;
end;
end;

end.
 
就是你的函数的实现部分没有加上类名
你是直接去写实现部分的框架的罢
建议在声明函数名的时候用“Ctrl+Shift+C”来产生
如果你发现这个快捷健不能用,先把你的金山词霸关了[:)]
 
多人接受答案了。
 
不好意思,小弟分数不多,谢谢各位!
 
后退
顶部