关于TinyXML创建对象的释放
/* * create 2011-12-29 * 生成迁移导出文件 * InputParm: int* result 执行结果 1[成功] 2[没有可以迁移的数据] 3[异常] * InputParm: AnsiString* fileName 文件名 * InputParm: AnsiString* filePath 文件路径 * InputParm: TADOConnection* adoconnection 数据库连接 * InputParm: AnsiString* exmsg 异常消息 * OutputParm: void */void TBillDataManage::Generate_Migration_XML( int* result, AnsiString* fileName, AnsiString* filePath, TADOConnection* adoconnection, AnsiString* exmsg ){ AnsiString sqlscript; sqlscript = "SELECT * FROM dt_ZXZ_Infos WHERE flag=1"; TADOQuery* query = new TADOQuery(NULL); try { try { query->Connection = adoconnection; query->SQL->Clear(); query->SQL->Add(sqlscript); query->Open(); int rec; rec = query->RecordCount; int row; row = 0; if(rec > 0) { TiXmlDocument* tiXmlDocument = new TiXmlDocument(); TiXmlDeclaration *pDeclaration = new TiXmlDeclaration("1.0", "", ""); //文档定义 tiXmlDocument->LinkEndChild(pDeclaration); TiXmlElement* xml_root = new TiXmlElement("DTT-DataExport"); tiXmlDocument->LinkEndChild(xml_root); TiXmlElement* xml_Date = new TiXmlElement("Date"); TiXmlText* xml_Date_text = new TiXmlText(Now().DateTimeString().c_str()); xml_Date->LinkEndChild(xml_Date_text); xml_root->LinkEndChild(xml_Date); TiXmlElement* xml_Type = new TiXmlElement("Type"); TiXmlText* xml_Type_text = new TiXmlText(DataMigration.c_str()); xml_Type->LinkEndChild(xml_Type_text); xml_root->LinkEndChild(xml_Type); TiXmlElement* xml_DataArea = new TiXmlElement("DataArea"); TiXmlElement* xml_DataCount = new TiXmlElement("DataCount"); TiXmlText* xml_DataCount_text = new TiXmlText(IntToStr(rec).c_str()); xml_DataCount->LinkEndChild(xml_DataCount_text); xml_DataArea->LinkEndChild(xml_DataCount); TiXmlElement* xml_DataVector = new TiXmlElement("DataVector"); while(!query->Eof) { row += 1; TiXmlElement* xml_Data = new TiXmlElement("Data"); xml_Data->SetAttribute("count", IntToStr(row).c_str()); TiXmlElement* xml_billnum = new TiXmlElement("billnum"); TiXmlText* xml_billnum_text = new TiXmlText(query->FieldByName("billnum")->AsString.c_str()); xml_billnum->LinkEndChild(xml_billnum_text); TiXmlElement* xml_billtype = new TiXmlElement("billtype"); TiXmlText* xml_billtype_text = new TiXmlText(query->FieldByName("billtype")->AsString.c_str()); xml_billtype->LinkEndChild(xml_billtype_text); TiXmlElement* xml_company = new TiXmlElement("company"); TiXmlText* xml_company_text = new TiXmlText(query->FieldByName("company")->AsString.c_str()); xml_company->LinkEndChild(xml_company_text); TiXmlElement* xml_companycode = new TiXmlElement("companycode"); TiXmlText* xml_companycode_text = new TiXmlText(query->FieldByName("companycode")->AsString.c_str()); xml_companycode->LinkEndChild(xml_companycode_text); TiXmlElement* xml_billyear = new TiXmlElement("billyear"); TiXmlText* xml_billyear_text = new TiXmlText(query->FieldByName("billyear")->AsString.c_str()); xml_billyear->LinkEndChild(xml_billyear_text); TiXmlElement* xml_inserttime = new TiXmlElement("inserttime"); TiXmlText* xml_inserttime_text = new TiXmlText(query->FieldByName("inserttime")->AsString.c_str()); xml_inserttime->LinkEndChild(xml_inserttime_text); TiXmlElement* xml_flag = new TiXmlElement("flag"); TiXmlText* xml_flag_text = new TiXmlText(query->FieldByName("flag")->AsString.c_str()); xml_flag->LinkEndChild(xml_flag_text); TiXmlElement* xml_insertcompany = new TiXmlElement("insertcompany"); TiXmlText* xml_insertcompany_text = new TiXmlText(query->FieldByName("insertcompany")->AsString.c_str()); xml_insertcompany->LinkEndChild(xml_insertcompany_text); xml_Data->LinkEndChild(xml_billnum); xml_Data->LinkEndChild(xml_billtype); xml_Data->LinkEndChild(xml_company); xml_Data->LinkEndChild(xml_companycode); xml_Data->LinkEndChild(xml_billyear); xml_Data->LinkEndChild(xml_inserttime); xml_Data->LinkEndChild(xml_flag); xml_Data->LinkEndChild(xml_insertcompany); xml_DataVector->LinkEndChild(xml_Data); //DELETE //delete xml_insertcompany_text; //delete xml_insertcompany; //delete xml_flag_text; //delete xml_flag; //delete xml_inserttime_text; //delete xml_inserttime; //delete xml_billyear_text; //delete xml_billyear; //delete xml_companycode_text; //delete xml_companycode; //delete xml_company_text; //delete xml_company; //delete xml_billtype_text; //delete xml_billtype; //delete xml_billnum_text; //delete xml_billnum; //delete xml_Data; query->Next(); } xml_DataArea->LinkEndChild(xml_DataVector); xml_root->LinkEndChild(xml_DataArea); //生成文件名称 *fileName = "DataMigration_" + Now().DateString() + ".XML"; AnsiString m_filePath = *filePath + *fileName; tiXmlDocument->SaveFile(m_filePath.c_str()); //delete xml_DataVector; //delete xml_DataCount_text; //delete xml_DataCount; //delete xml_DataArea; //delete xml_Type_text; //delete xml_Type; //delete xml_Date_text; //delete xml_Date; //delete xml_root; //delete pDeclaration; delete tiXmlDocument; *result = RESULT_SUCESS; }else { *result = RESULT_NODATA; } }catch(Exception &ex) { *result = RESULT_EXCEPTION; *exmsg = ex.Message; } }__finally { query->Close(); query->Free(); }}