请教各位一个自定义函数的问题..........(50分)

H

hj6

Unregistered / Unconfirmed
GUEST, unregistred user!
请问大家以下这个自定义函数有什么错误的地方,请指点:
function CopyFromTQueryToTTable(Query: TQuery;
var Table: TTable;
var BMove: TBatchMove): Boolean;
var
i: Integer;
begin
Result := False;
try
with Table do begin
Close;
FieldDefs.clear;
for i := 0 to Query.FieldDefs.Count-1 do
FieldDefs.Add(Query.FieldDefs.Items.Name,
Query.FieldDefs.Items.DataType,
Query.FieldDefs.Items.Size,
Query.FieldDefs.Items.Required);
IndexDefs.Clear;
end;
Table.CreateTable;
except
MessageDlg( 'An error has ocurred while creating the tmp table ' + #13 +
'Check that all the fields of the original table are compatible
with that of destination.' , mtError,[mbCancel], 0 );
Exit;
end;
with Table2 do begin
Close;
DataBaseName := Directory1.Directory;
TableName := 'Tmp.dbf';
TableType := ttdefault;
end;


{# Execute the query copy}
with BMove do begin
Source := Query;
Destination := Table;
Mode := batAppend;
Execute;
end;
Table.Close;

Result := True;
end;
在public去定义的CopyFromTQueryToTTable函数。我用Delphi4+win95。我觉得从字面看
没有什么问题,但是一运行就提示说这个函数和前面定义的类型不同,请大家帮忙。谢谢!
 
小弟不知道Table2 是哪来的?
 
Make sure the Table is not active first.
说这个函数和前面定义的类型不同??

 
可以把你如何调用CopyFromTQueryToTTable的 语句写出来吗?
 
系统提示的出错语句是:
Unsatisfied forward or external declaration 'Tform1.CopyFromTQueryToTTable'
首先感谢大家的指点。我的意思是从一个表(Table1)里用SQL语句查找出有用的记录,
但是查找出来的记录有时并不需要把原来的数据库的所有的字段都罗列出来,大多数
情况是只要其中的几个字段就行了。所以要根据查找出来的数据表(Query1)而生成一个
新的临时的数据表(Table2),然后在用BachMove1把Query1里的数据移动到Table2里。
以便我做进一步的数据处理,如把查找出来的记录导入到文本文件或Office文件里。
比如在查找出来的数据表(Query1)里有两个字段,两条记录,那么(Table2)也就相应的有
两个字段,两条记录,而且字段的类型、长度等参数都一样。谢谢!!!
以下是调用函数的CopyFromTQueryToTTable的语句,我把它定义成MoveFromQuery1ToTable2
过程:
procedure Tform1.MoveFromQuery1ToTable2;
var
i: Integer;
begin
{To create new tmp table in the indicated directory}
with Table2 do begin
Close;
DataBaseName := Directory1.Directory;
TableName := 'Tmp.dbf';
TableType := ttdufault;
end;
if not CopyFromTQueryToTTable(Query1, Table2, BMove1) then begin
ShowMessage('Error when passing over data from the Query to the table Tmp.dbf');
Exit;
end;
end;
再次感谢大家的帮忙!谢谢!!!
 
系统提示的出错语句是:
Unsatisfied forward or external declaration 'Tform1.CopyFromTQueryToTTable'
首先感谢大家的指点。我的意思是从一个表(Table1)里用SQL语句查找出有用的记录,
但是查找出来的记录有时并不需要把原来的数据库的所有的字段都罗列出来,大多数
情况是只要其中的几个字段就行了。所以要根据查找出来的数据表(Query1)而生成一个
新的临时的数据表(Table2),然后在用BachMove1把Query1里的数据移动到Table2里。
以便我做进一步的数据处理,如把查找出来的记录导入到文本文件或Office文件里。
比如在查找出来的数据表(Query1)里有两个字段,两条记录,那么(Table2)也就相应的有
两个字段,两条记录,而且字段的类型、长度等参数都一样。谢谢!!!
以下是调用函数的CopyFromTQueryToTTable的语句,我把它定义成MoveFromQuery1ToTable2
过程:
procedure Tform1.MoveFromQuery1ToTable2;
var
i: Integer;
begin
{To create new tmp table in the indicated directory}
with Table2 do begin
Close;
DataBaseName := Directory1.Directory;
TableName := 'Tmp.dbf';
TableType := ttdufault;
end;
if not CopyFromTQueryToTTable(Query1, Table2, BMove1) then begin
ShowMessage('Error when passing over data from the Query to the table Tmp.dbf');
Exit;
end;
end;
再次感谢大家的帮忙!谢谢!!!
 
Unsatisfied forward or external declaration 'Tform1.CopyFromTQueryToTTable'
这个提示并不是说你的函数有问题,而是说,你在未声明此函数之前就调用它了。试试以下方法:
1。在所有函数之前声明这个函数;
2。在FORM的定义部分声明这个函数。
 
Unsatisfied forward or external declaration 'Tform1.CopyFromTQueryToTTable'
咳,这是说你在TForm1中有这个过程的定义,但是编译的时候没有找到这个过程的具体代码
 
不要告诉我,在定义处改为以下语句,就行了:
function Tform1.CopyFromTQueryToTTable(Query: TQuery;
var Table: TTable;
var BMove: TBatchMove): Boolean;

 
自定义函数如果不在FORM对象内部声明,将不能直接引用FORM对象的元素
如果在PUBLIC,PRIVATE中定义的话,必须在实现部分加入FORM对象名称的前缀
自定义函数如果确实不在FORM对象内部,则必须写在引用部分的前面,除非标明FORWARD后缀

所以定义部分应该为
...
function CopyFromTQueryToTTable(Query: TQuery;
var Table: TTable;
var BMove: TBatchMove): Boolean;
...

所以实现部分的定义应该为

function Tform1.CopyFromTQueryToTTable(Query: TQuery;
var Table: TTable;
var BMove: TBatchMove): Boolean;
 
再次感谢大家的帮助!谢谢!!!
大家能否用语句直接实现这个功能而不用函数?如果可以,请给我寄一份。谢谢!

 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
655
import
I
顶部