关于delphi 返回函数 如何使用的 具体如下
UNIT2想作为公共单元使用,但会提示一些错误[Error]unit2.pas(6):Undeclaredidentifier:'TStringList'[Error]u...
UNIT2 想作为公共单元使用,但会提示一些错误
[Error] unit2.pas(6): Undeclared identifier: 'TStringList'
[Error] unit2.pas(8): Undeclared identifier: 'DWord'
[Error] unit2.pas(15): Undeclared identifier: 'strLen'
[Error] unit2.pas(17): Missing operator or semicolon
[Warning] unit2.pas(45): Comparing signed and unsigned types - widened both operands
[Warning] unit2.pas(45): Comparing signed and unsigned types - widened both operands
[Error] unit2.pas(48): Missing operator or semicolon
[Warning] unit2.pas(57): Comparing signed and unsigned types - widened both operands
[Error] unit2.pas(59): Missing operator or semicolon
[Error] unit2.pas(65): Missing operator or semicolon
[Fatal Error] main.pas(181): Could not compile used unit 'unit2.pas'
请问下边的错在哪
unit unit 2;
interface
implementation
function SplitString(pString:Pchar;psubString:PChar):TStringList;
var
nSize,SubStringSize:DWord;
intI,intJ,intK:DWORD;
ts:TStringList;
curChar:Char;
strString:string;
strsearchSubStr:string;
begin
nSize:=strLen(pString);
SubStringSize:=strLen(PSubString);
ts:=TStringList.Create;
strstring:='';
inti:=0;
while intI<=(nSize-1) do
begin
if (nsize-inti)>= substringSize then
begin
if ((PString+intI)^=pSubString^) then
begin
intk:=inti;
strSearchSubStr:='';
curchar:=(pstring+intk)^;
strsearchSubStr:=strSearchSubStr+Curchar;
intk:=intk+1;
for intj:= 1 to SubStringSize-1 do
begin
if ((pString+intk)^=(PSubString+intj)^) then
begin
curchar:=(pstring+intk)^;
intk:=intk+1;
strsearchSubStr:=strSearchSubStr+Curchar;
end
else begin
inti:=intk;
strString:=strString+strSearchSubStr;
break;
end;
end;
if (intJ=substringSize) or (SubStringSize=1) then
begin
inti:=intk;
ts.add(strstring);
strstring:='';
end;
end
else
begin
curChar:=(pString+inti)^;
strstring:=strstring+curchar;
inti:=inti+1;
end;
if inti=nsize then
begin
ts.Add(strString);
strString:='';
end;
end
else
begin
strString:=strstring+string(pString+inti);
ts.Add(strstring);
inti:=nsize;
end;
end;
Result:=ts;
end;
end. 展开
[Error] unit2.pas(6): Undeclared identifier: 'TStringList'
[Error] unit2.pas(8): Undeclared identifier: 'DWord'
[Error] unit2.pas(15): Undeclared identifier: 'strLen'
[Error] unit2.pas(17): Missing operator or semicolon
[Warning] unit2.pas(45): Comparing signed and unsigned types - widened both operands
[Warning] unit2.pas(45): Comparing signed and unsigned types - widened both operands
[Error] unit2.pas(48): Missing operator or semicolon
[Warning] unit2.pas(57): Comparing signed and unsigned types - widened both operands
[Error] unit2.pas(59): Missing operator or semicolon
[Error] unit2.pas(65): Missing operator or semicolon
[Fatal Error] main.pas(181): Could not compile used unit 'unit2.pas'
请问下边的错在哪
unit unit 2;
interface
implementation
function SplitString(pString:Pchar;psubString:PChar):TStringList;
var
nSize,SubStringSize:DWord;
intI,intJ,intK:DWORD;
ts:TStringList;
curChar:Char;
strString:string;
strsearchSubStr:string;
begin
nSize:=strLen(pString);
SubStringSize:=strLen(PSubString);
ts:=TStringList.Create;
strstring:='';
inti:=0;
while intI<=(nSize-1) do
begin
if (nsize-inti)>= substringSize then
begin
if ((PString+intI)^=pSubString^) then
begin
intk:=inti;
strSearchSubStr:='';
curchar:=(pstring+intk)^;
strsearchSubStr:=strSearchSubStr+Curchar;
intk:=intk+1;
for intj:= 1 to SubStringSize-1 do
begin
if ((pString+intk)^=(PSubString+intj)^) then
begin
curchar:=(pstring+intk)^;
intk:=intk+1;
strsearchSubStr:=strSearchSubStr+Curchar;
end
else begin
inti:=intk;
strString:=strString+strSearchSubStr;
break;
end;
end;
if (intJ=substringSize) or (SubStringSize=1) then
begin
inti:=intk;
ts.add(strstring);
strstring:='';
end;
end
else
begin
curChar:=(pString+inti)^;
strstring:=strstring+curchar;
inti:=inti+1;
end;
if inti=nsize then
begin
ts.Add(strString);
strString:='';
end;
end
else
begin
strString:=strstring+string(pString+inti);
ts.Add(strstring);
inti:=nsize;
end;
end;
Result:=ts;
end;
end. 展开
1个回答
展开全部
interface节是空白,怎么能不出错。要是不清楚这一节怎么写,把窗体单元的这一节复制过来,用到字符处理的再加上StrUtils单元。
更多追问追答
追问
报错的那部分,是没有加,TStringList这个 不知道应该加什么单元 原来是StrUtils
那里面是Dword strLen 应该也是这个单元的吧 ?
顺便问下,如果我有固定的一个文本 应该如何导入到DBgird里面去 例如 不一定是数字可能是中、英文、数字
1,2,3,4,5,
3,4,5,6,5,
或者说应该是导入到table里面吧
追答
TStringList是一个常用类,当然在Classes单元。基本的字符串函数通常在SysUtils单元,更多的字符串函数则在StrUtils单元。要知道一个函数在哪个单元很简单,在代码中打出这个函数名,光标放在函数上,按F1打开帮助就有说明。DBgird是数据控制组件,要通过数据源连接数据集,数据集又连接数据表才能显示数据,单纯的文本是不能显示到DBgird中的,不过利用OLEDB数据库引擎,可以把一个这样格式的文本文件作为数据表连接,从而显示在DBgird中。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询