下面的代码是一个函数,主程序是一个循环,每循环一次调用一次这个函数,<br>共循环15000次。文件的创建、关闭是在主程序中。写文件的时候使用了自己写<br>的函数。<br>procedure Tfrm_IDXML.makesubcategory(qrtemp:TAdoquery);<br>var<br> str : string;<br> i : integer;<br> levelstr,orderstr : string;<br>begin<br>//<br> with dm do<br> begin<br> levelstr := '';<br> str := '';<br> str := str + 'select b.category_id,b.category_xml ';<br> str := str + ' from FEE_category_xml b,category a,category_temp c ';<br> str := str + ' where a.category_id = b.category_id ';<br> str := str + ' and a.category_id = c.category_id ';<br> str := str + ' and c.resource_count > 0 ';<br> str := str + ' and a.inuse = 1 ';<br> str := str + ' and a.father_id = ' + qrtemp.fieldbyname('category_id').asstring;<br> levelstr := ' and a.level_id = 0 ';<br> orderstr := ' order by a.orderno ';<br><br> runsql(str+levelstr+orderstr,qr_func);<br>{}<br> writeutf8('<CurrentCategories>');<br> writeutf8(getCategoryNavStr(qrtemp.fieldbyname('category_longcode').asstring<br> ,qrtemp.fieldbyname('category_longname').asstring));<br> writeutf8('</CurrentCategories>');<br><br><br> if qr_func.RecordCount > 0 then<br> begin<br> writeutf8('<StyleCategories>' +<br> ' <First><![CDATA[1]]></First>' +<br> ' <Last><![CDATA['+inttostr(qr_func.recordcount)+']]></Last>' +<br> ' <Total><![CDATA['+inttostr(qr_func.RecordCount)+']]></Total>' +<br> ' <SubCatsResults>');<br><br> for i := 0 to qr_func.RecordCount - 1 do<br> begin<br> writeutf8(qr_func.fieldbyname('category_xml').asstring);<br> qr_func.Next;<br> end;//end for<br><br> writeutf8(' </SubCatsResults>'+<br><br> '</StyleCategories>');<br><br> end;//end if<br> {}<br> qr_func.Close;<br><br> str := '';<br> str := str + 'select b.category_id,b.category_xml ';<br> str := str + ' from FEE_category_xml b,category a,category_temp c ';<br> str := str + ' where a.category_id = b.category_id ';<br> str := str + ' and a.category_id = c.category_id ';<br> str := str + ' and c.resource_count > 0 ';<br> str := str + ' and a.inuse = 1 ';<br> str := str + ' and a.father_id = ' + qrtemp.fieldbyname('category_id').asstring;<br> levelstr := ' and a.level_id = 1 ';<br> orderstr := ' order by a.orderno ';<br><br> runsql(str+levelstr+orderstr,qr_func);<br> if qr_func.RecordCount < 1 then<br> begin<br> qr_func.Close;<br> exit;<br> end;<br> writeutf8('<ContentCategories>' +<br> ' <First><![CDATA[1]]></First>' +<br> ' <Last><![CDATA['+inttostr(qr_func.recordcount)+']]></Last>' +<br> ' <Total><![CDATA['+inttostr(qr_func.RecordCount)+']]></Total>' +<br> ' <SubCatsResults>');<br><br> if qr_func.RecordCount > 0 then<br> begin<br> for i := 0 to qr_func.RecordCount - 1 do<br> begin<br> writeutf8(qr_func.fieldbyname('category_xml').asstring);<br> qr_func.Next;<br> end;//end for<br><br> end;//end if<br> writeutf8(' </SubCatsResults>' +<br> '</ContentCategories>');<br><br> qr_func.Close;<br><br><br> end;//end with<br><br>end;//end makesubcategory<br><br>//写文件的函数<br>procedure Tfrm_IDXML.writeutf8(s:string);<br>begin<br> if cb_code.Checked then<br> writeln(f,ansitoutf8(s))<br> else<br> writeln(f,s);<br>end;<br><br>