请问为什么函数不能得到正确的返回值(50分)

  • 主题发起人 主题发起人 Buffer
  • 开始时间 开始时间
B

Buffer

Unregistered / Unconfirmed
GUEST, unregistred user!
程序如下:
procedure TForm1.CreateStartMenu(const WorkDir: string;
var MenuItem: TMenuItem);
Var
SearchRec:TSearchRec;
FWorkDir:String;
SubMenuItem:TMenuItem;
begin
FWorkDir :=WorkDir;
if (FindFirst(FWorkDir +'/*.*', faDirectory,SearchRec)=0) then
begin
repeat
if (SearchRec.Attr and faDirectory = faDirectory) then
begin
if (SearchRec.Name <>'.')and (SearchRec.Name <>'..') then
begin
SubMenuItem:=TMenuItem.Create(Self);
SubMenuItem.Caption :=SearchRec.Name;
MenuItem.Add(SubMenuItem);
//子目录
CreateStartMenu(FWorkDir+'/'+SearchRec.Name,SubMenuItem);
end;
end;
until FindNext(SearchRec) <> 0;
end;
FindClose(SearchRec);
if (FindFirst(FWorkDir +'/*.*', faDirectory,SearchRec)=0) then
begin
repeat
if (SearchRec.Attr and faDirectory <> faDirectory) then
begin
SubMenuItem:=TMenuItem.Create(MenuItem);
SubMenuItem.Caption :=Copy(SearchRec.Name,1,Length(SearchRec.Name)-4);
if Length(SubMenuItem.Caption) >25 then
SubMenuItem.Caption :=Copy(SubMenuItem.Caption,1,25)+'...';
SubMenuItem.Hint := GetShorCutTarget(FWorkDir+SearchRec.Name);
MenuItem.Add(SubMenuItem);
end;
until FindNext(SearchRec) <> 0;
end;
FindClose(SearchRec);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
CreateStartMenu('E:/Documents and Settings/Administrator/「开始」菜单/程序',Form1.a1);
end;

function TForm1.GetShorCutTarget(Shortcutfilename: string): string;
var
Psl:IShellLink;
Ppf:IPersistFile;
WideName:Array [0..MAX_PATH] of WideChar;
pResult:Array [0..MAX_PATH-1] Of Char;
Data:TWin32FindData;
const
IID_IPersistFile: TGUID = (
D1:$0000010B;
D2:$0000;
D3:$0000;
D4:($C0,$00,$00,$00,$00,$00,$00,$46));
begin
CoCreateInstance(CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER, IID_IShellLinkA ,psl);
psl.QueryInterface(IID_IPersistFile,ppf);
MultiByteToWideChar(CP_ACP, 0, pChar(ShortcutFilename), -1, WideName, Max_Path);
ppf.Load(WideName,STGM_READ);
psl.Resolve(0,SLR_ANY_MATCH);
psl.GetPath( @pResult,MAX_PATH,Data,SLGP_UNCPRIORITY);
Result:=StrPas(@pResult);
end;
将快捷方式写入自己的菜单中.当过程CreateStartMenu调用函数GetShorCutTarget:
SubMenuItem.Hint := GetShorCutTarget(FWorkDir+SearchRec.Name);时函数返回值总为空
请各位富翁帮瞧瞧.
 
谁有工夫读这么长的代码?
 
问题已解决.GetShorCutTarget(FWorkDir+'/'+SearchRec.Name);
多谢各位关注.
 
问题已解决
 
呵什么原因?
代码太长不想看:)
 
路径和文件名之间少加了一个'/'.
以后要细心奥
 
接受答案了.
 
后退
顶部