请问如何在函数中返回数组? ( 积分: 100 )

  • 主题发起人 主题发起人 徐辰仲
  • 开始时间 开始时间

徐辰仲

Unregistered / Unconfirmed
GUEST, unregistred user!
Function&nbsp;Tstr(tmp:string;Sstr:char):string;<br>var<br>I:integer;<br>aa:PChar;<br>begin<br>for&nbsp;I:=1&nbsp;to&nbsp;4&nbsp;do<br>begin<br>aa:=AnsiStrScan(PChar(Trim(tmp)),Sstr);<br>num:=Trim(LeftStr(Trim(tmp),Length(trim(tmp))-Length(trim(strpas(aa)))));<br>Tmp:=Trim(strpas(aa));<br>end;<br><br>end;<br>请问我调用函数是想要返回出num这个数组,应该如何修改?麻烦各位大大了
 
用TSTRINGLIST,举例说明<br><br>function&nbsp;TForm1.test(TmpStr:&nbsp;string):&nbsp;TStringlist;<br>begin<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;TStringList.Create;<br>&nbsp;&nbsp;Result.Add(('aa'));<br>&nbsp;&nbsp;Result.Add(('bb'));<br>&nbsp;&nbsp;Result.Add(('cc'));<br>end;
 
function&nbsp;getIntArray(nSize&nbsp;:&nbsp;integer,var&nbsp;res:array&nbsp;of&nbsp;Integer;)&nbsp;:&nbsp;boolean;<br>begin<br>&nbsp;&nbsp;setLength(res,nSize);<br>&nbsp;&nbsp;...<br>&nbsp;&nbsp;result&nbsp;:=&nbsp;true;<br>end<br><br><br><br>在前面定义了<br>PIntArray&nbsp;<br>然后再写<br>function&nbsp;getIntArray(nSize&nbsp;:&nbsp;integer)&nbsp;:&nbsp;PIntArray;<br>var<br>&nbsp;&nbsp;res&nbsp;:&nbsp;PIntArray;<br>begin<br>&nbsp;&nbsp;setLength(res,nSize);<br>&nbsp;&nbsp;...<br>&nbsp;&nbsp;result&nbsp;:=&nbsp;res;<br>end;
 
Function&nbsp;Tstr(tmp:string;Sstr:char):array&nbsp;[4]&nbsp;of&nbsp;string;<br>var<br>&nbsp;&nbsp;I:integer;<br>&nbsp;&nbsp;aa:PChar;<br>begin<br>&nbsp;&nbsp;for&nbsp;I:=1&nbsp;to&nbsp;4&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;aa:=AnsiStrScan(PChar(Trim(tmp)),Sstr);<br>&nbsp;&nbsp;&nbsp;&nbsp;num:=Trim(LeftStr(Trim(tmp),Length(trim(tmp))-Length(trim(strpas(aa)))));<br>&nbsp;&nbsp;&nbsp;&nbsp;Tmp:=Trim(strpas(aa));<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;result:=num;<br>end;
 
定义指针数组或全局数组啊!
 
终于成功了原来可以这样写<br>const<br>&nbsp;&nbsp;constr&nbsp;:String&nbsp;=&nbsp;'aaa/bbb/ccc/ddd';<br>var<br>&nbsp;&nbsp;strs&nbsp;:TStrings;<br>&nbsp;&nbsp;i&nbsp;:Integer;<br>begin<br>&nbsp;&nbsp;strs&nbsp;:=&nbsp;TStringList.Create;<br>&nbsp;&nbsp;strs.Delimiter&nbsp;:=&nbsp;'/';<br>&nbsp;&nbsp;strs.DelimitedText&nbsp;:=&nbsp;constr;<br>&nbsp;&nbsp;for&nbsp;i&nbsp;:=&nbsp;0&nbsp;to&nbsp;Strs.Count-1&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;ShowMessage(Strs);<br>特别谢谢李翔鹏,你说的很清楚,也谢谢各位大大,bbscom你的方法我试了下好像失败了
 
谢谢各位了,[:D]散分了
 
返回数组?<br>解决实际问题?<br>技术?<br>垃圾?<br>。。。<br>鸟就是鸟。。。
 
后退
顶部