帮我看看这段语句有什么问题???(50分)

  • 主题发起人 主题发起人 carem1
  • 开始时间 开始时间
C

carem1

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么我不可以按照sharenumber循环地删除所有共享??<br>function NetShareDel(ServerName: Widestring; NetName: Widestring;<br>&nbsp; Reserved: DWord): Integer; stdcall; external 'netapi32.dll' name<br>&nbsp; &nbsp; 'NetShareDel';<br>.............................<br>...........................<br>var<br>&nbsp; netname: array[0..255] of WideChar;<br>&nbsp; ServerName: widestring;<br>&nbsp; sharpnumber:integer;<br>begin<br>&nbsp; if strcmd = 'aaa'then //取消所有已经共享的磁盘或者目录<br>&nbsp; begin<br>&nbsp; &nbsp; ServerName := '';<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; for sharpnumber := sharpnumber to -1 do<br>&nbsp; &nbsp; &nbsp;StringToWideChar('监控共享' + IntToStr(sharpnumber), netname, 255);<br>&nbsp; &nbsp; &nbsp; NetShareDel(ServerName, netname, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; sharpnumber := sharpnumber - 1; &nbsp; <br>&nbsp; end;<br>end;
 
...<br>var<br>&nbsp; netname: array[0..255] of WideChar;<br>&nbsp; ServerName: widestring;<br>&nbsp; sharpnumber:integer;<br>begin<br>&nbsp; if strcmd = 'aaa'then //取消所有已经共享的磁盘或者目录<br>&nbsp; begin<br>&nbsp; &nbsp; ServerName := ''; <br>&nbsp; &nbsp; // 原来放在这里的那个个begin 位置错了,它应该是属于循环体的 &nbsp; <br>&nbsp; &nbsp; for sharpnumber := sharpnumber to -1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; StringToWideChar('监控共享' + IntToStr(sharpnumber), netname, 255);<br>&nbsp; &nbsp; &nbsp; NetShareDel(ServerName, netname, 0);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; sharpnumber := sharpnumber - 1; &nbsp; <br>&nbsp; end;<br>end;
 
不对~!!!这样照样循环不了
 
是循环不了还是删除不了?
 
我在<br>sharpnumber := sharpnumber - 1; &nbsp; <br>后面加了showmessage语句,但是只可以显示1次!<br><br>另外删除哪里也是有问题~!!
 
...<br>var<br>&nbsp; netname: array[0..255] of WideChar;<br>&nbsp; ServerName: widestring;<br>&nbsp; sharpnumber:integer;<br>begin<br>&nbsp; if strcmd = 'aaa'then //取消所有已经共享的磁盘或者目录<br>&nbsp; begin<br>&nbsp; &nbsp; ServerName := ''; <br>&nbsp; &nbsp; // 原来放在这里的那个个begin 位置错了,它应该是属于循环体的 &nbsp; <br>&nbsp; &nbsp; for sharpnumber := sharpnumber to -1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; StringToWideChar('监控共享' + IntToStr(sharpnumber), netname, 255);<br>&nbsp; &nbsp; &nbsp; NetShareDel(ServerName, netname, 0);<br>&nbsp; &nbsp; end;<br>错:(应该在上一个end前面) &nbsp; &nbsp;sharpnumber := sharpnumber - 1; &nbsp; <br>&nbsp; end;<br>end; &nbsp;<br><br>
 
to socid <br><br>&nbsp; &nbsp; &nbsp; NetShareDel(ServerName, netname, 0);<br>&nbsp; &nbsp; &nbsp; sharenumber := sharenumber - 1;<br><br>这样??编译地时候还是出错
 
循环改为:<br>repeat<br>&nbsp; &nbsp; &nbsp; StringToWideChar('监控共享' + IntToStr(sharpnumber), netname, 255);<br>&nbsp; &nbsp; &nbsp; NetShareDel(ServerName, netname, 0);<br>&nbsp; &nbsp; &nbsp; dec(sharpnumber);<br>until sharpnumber=-1;<br>试下?<br>可能是用for do的时候循环参数和边界值不能用同一个变量
 
当然会错了,在for 的循环体里面是不允许有改变循环控制变量值的语句的。
 
&nbsp; &nbsp;for sharpnumber := sharpnumber to -1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; StringToWideChar('监控共享' + IntToStr(sharpnumber), netname, 255);<br>&nbsp; &nbsp; &nbsp; NetShareDel(ServerName, netname, 0);<br>&nbsp; &nbsp; end;<br>错:(应该在上一个end前面) &nbsp; &nbsp;sharpnumber := sharpnumber - 1; &nbsp; <br>&nbsp; end;<br><br>晕菜,以上的代码算什么啊?<br>sharpnumber 没有初始化<br><br>能够这样吗? sharpnumber := sharpnumber - 1;<br><br>用downto 可以吧.<br>
 
至于删除那里的问题,我想可能是没有为netname设置正确的字符串空结束标志的原因,可以改成这样--<br>var<br>...<br>&nbsp; s:string; &nbsp;// 定义多一个临时的字符串变量<br>...<br>repeat<br>&nbsp; s:='监控共享' + IntToStr(sharpnumber);<br>&nbsp; StringToWideChar(s,netname, 255);<br>&nbsp; netname[Length(s)]:=#0;<br>&nbsp; NetShareDel(ServerName, netname, 0);<br>&nbsp; dec(sharpnumber);<br>until sharpnumber=-1;<br>
 
后退
顶部