
关于Object Pascal的几个语法问题 50
最近在编一个项目从delphiXE2移植到LazarusOP上,但以下代码在XE2下编译通过,但在Lazarus下确报错://======================...
最近在编一个项目从delphi XE2移植到Lazarus OP上,但以下代码在XE2下编译通过,但在Lazarus下确报错:
//===================================================================
procedure TFrmMain.RemoveDir(sDirectory: String);
var sr:TSearchRec;
sPath,sFile:string;
begin
if Copy(sDirectory,length(sDirectory),1)<>'\' then
sPath:=sDirectory+'\'
else
sPath:=sDirectory;
if FindFirst(sPath+'*.*',faAnyFile,sr)=0 then
begin
Repeat
sFile:=sr.Name;
if (sFile='.') or (sFile='..') then continue;
sFile:=sPath+sr.Name;
if (sr.Attr and faDirectory)<>0 then
begin
Application.ProcessMessages;
removeDir(sFile);
end
else if (sr.Attr and faAnyFile) = sr.Attr then
Application.ProcessMessages;
DeleteFile(sFile);//这句报错:Got "AnsiString", expected "PChar"
until FindNext(sr)<>0 ;
FindClose(sr);//这句报错:Got "TSearchRec", expected "LongWord"
end;
RemoveDir(sPath);
end;
查看了它自带的inc文件,也是这样定义的,为什么报错?还有Object Pascal使用CreateThread会导致内存故障,为什么?真是搞不懂了。(请不要说使用XE2,现在就要移植到lazarus上) 展开
//===================================================================
procedure TFrmMain.RemoveDir(sDirectory: String);
var sr:TSearchRec;
sPath,sFile:string;
begin
if Copy(sDirectory,length(sDirectory),1)<>'\' then
sPath:=sDirectory+'\'
else
sPath:=sDirectory;
if FindFirst(sPath+'*.*',faAnyFile,sr)=0 then
begin
Repeat
sFile:=sr.Name;
if (sFile='.') or (sFile='..') then continue;
sFile:=sPath+sr.Name;
if (sr.Attr and faDirectory)<>0 then
begin
Application.ProcessMessages;
removeDir(sFile);
end
else if (sr.Attr and faAnyFile) = sr.Attr then
Application.ProcessMessages;
DeleteFile(sFile);//这句报错:Got "AnsiString", expected "PChar"
until FindNext(sr)<>0 ;
FindClose(sr);//这句报错:Got "TSearchRec", expected "LongWord"
end;
RemoveDir(sPath);
end;
查看了它自带的inc文件,也是这样定义的,为什么报错?还有Object Pascal使用CreateThread会导致内存故障,为什么?真是搞不懂了。(请不要说使用XE2,现在就要移植到lazarus上) 展开
展开全部
用这个就行:
SysUtils.FindClose(SR);
这个。。 Windows 这个单元 (unit)也有一个叫做FindClose的函数.而你需要的是SysUtils单元里的FindClose函数。这是问题所在。所以用SysUtils.FindClose(SR); 应该可以解决问题~
另外,PChar应该可以解决另一个报错处的问题。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DeleteFile(sFile);//这句报错:Got "AnsiString", expected "PChar"
DeleteFile(pchar(sFile));//你这样试试呢!
DeleteFile(pchar(sFile));//你这样试试呢!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只是做任务.......路过
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询