求助有关Delphi的Unit
在网上看到很多有关Delphi的Unit的涵数,不知道怎么用,另外我想自己写一个.可是有个问题.
比如下面的
unit UCommonOperate;
interface
uses
Classes,udbSQL;
type
UdbQuery1 = TUdbQuery;
function GetBookList: TStrings;
function GetBookIndex(Str: String): String;
implementation
uses main;
function GetBookList: TStrings;
var
returnResult:TStrings;
begin
returnResult := TStrings.Create;
mainf.UdbQuery1.SQL.Clear;
mainf.UdbQuery1.SQL.Add('select value from selfbook');
mainf.UdbQuery1.Open;
mainf.UdbQuery1.First;
while not mainf.UdbQuery1.Eof do
begin
returnResult.Add(mainf.UdbQuery1.Fields[0].AsString);
mainf.UdbQuery1.Next;
end;
mainf.UdbQuery1.close;
GetBookList := returnResult;
end;
为什么我如果去掉 UdbQuery1 = TUdbQuery;这行,就会出下面这行.
[Error] UCommonOperate.pas(9): Identifier expected but 'FUNCTION' found
而且为什么UdbQuery1 = TUdbQuery的=号前加冒号会有错,
我如何在这里定义一个全局的TUdbQuery变量
,还有我这段代码如何在另外的Form里面使用
问题点数:40、回复次数:5Top
1 楼xixuemao(钱不是问题,问题是没钱)回复于 2005-08-03 11:55:29 得分 8
全局变量在
var
....
.....
implementation//在上面定义即可。
其它form需要用这个单元,直接在uses里加入UCommonOperate就可以了。Top
2 楼xixuemao(钱不是问题,问题是没钱)回复于 2005-08-03 11:57:18 得分 8
type
UdbQuery1 = TUdbQuery;
function GetBookList: TStrings;
function GetBookIndex(Str: String): String;
把type去掉,然后把 UdbQuery1 = TUdbQuery;放到implementation上面定义。Top
3 楼lianshaohua(永远深爱一个叫“...”的好女孩儿!)回复于 2005-08-03 12:00:17 得分 8
type
UdbQuery1 = TUdbQuery;
function GetBookList: TStrings;
function GetBookIndex(Str: String): String;
//这在类型自定义,如果你去掉了UdbQuery1 = TUdbQuery;,那么type去定义谁?UdbQuery1 = TUdbQuery;这句不是Delphi中的赋值语句,所以不能在前边加冒号;其它的楼上已回答了Top
4 楼tjianliang(乡关何处)回复于 2005-08-03 12:45:18 得分 8
type
UdbQuery1 = TUdbQuery;
function GetBookList: TStrings;
function GetBookIndex(Str: String): String;
这两个函数写在这里是全局函数,type是类型定义部分,类型定义是用=,不是:= ,比如
TForm1 = class(TForm)
...
end;
这样写可能清楚一点:
type
UdbQuery1 = TUdbQuery;
function GetBookList: TStrings;
function GetBookIndex(Str: String): String;
Top
5 楼liuyan55(ayan)回复于 2005-08-03 18:28:16 得分 8
upTop




