我在遗留代码中使用带有单向属性= False的TIBQuery(Interbase)有很多方法。问题在于用户有时会出现内存异常。 我怀疑可以通过将此属性设置为True来解决此问题,因为不需要缓存记录。TIBQuery.Unidirectional = True。我如何重写代码?
当然,我不希望冲破旧的代码,但我也想解决这个问题。
下面是一个代码示例(未完成,因为尺寸的):
procedure TAnalyzeForm.CostByInvoice;
begin
try
qryReport.Close;
qryReport.Open;
qryReport.Last;
qryReport.First;
if qryReport.RecordCount > 0 then
begin
for i := 0 to qryReport.RecordCount - 1 do
begin
vInvoiceNo := Format('%-8s', [qryReport.FieldValues['InvoiceNo']]);
vDeptId := Format('%8s', [qryReport.FieldValues['DepartmentId']]);
vOrgName := Format('%-22s', [qryReport.FieldValues['OrgName']]);
vInvDate := qryReport.FieldValues['InvoiceDate'];
vInvNetCur := qryReport.FieldValues['InvNetCur'];
vInvVatCur := qryReport.FieldValues['InvVatCur'];
vInvTotCur := qryReport.FieldValues['InvTotCur'];
vInvCur := qryReport.FieldValues['UnitId'];
vTotNet := vTotNet + qryReport.FieldValues['InvNetValue'];
vTotVat := vTotVat + qryReport.FieldValues['InvVatValue'];
vTotTot := vTotTot + (qryReport.FieldValues['InvNetValue'] + qryReport.FieldValues['InvVatValue']);
grdCost.Cells[1, i+1] := vInvoiceNo;
grdCost.Cells[2, i+1] := vDeptId + ' ' + vOrgName;
grdCost.Cells[3, i+1] := FormatDateTime('dd.mm.yyyy', vInvDate);
grdCost.Cells[4, i+1] := Format('%12.2f', [vInvNetCur]);
grdCost.Cells[5, i+1] := Format('%12.2f', [vInvVatCur]);
grdCost.Cells[6, i+1] := Format('%12.2f', [vInvTotCur]);
grdCost.Cells[7, i+1] := 'EUR';
grdCost.RowCount := i+1 + 1;
qryReport.next;
end;
txtNetCost.Caption := Format('%12.2f', [vTotNet]);
txtVatCost.Caption := Format('%12.2f', [vTotVat]);
txtTotCost.Caption := Format('%12.2f', [vTotTot]);
SummaryInfo(stSummaryInfoCost, 'Number of costinvoices: ' + IntToStr(qryReport.RecordCount), time, true);
end
else
MessageDlg('nothing found!', mtInformation, [mbOk], 0);
finally
qryReport.Close;
end;
end;
的重要的变量是qryReport这是一个TIBQuery。我想重写它,所以我可以设置TIBQuery.Unidirectional = True。 qryReport在许多不同的SQL地方被重用,所以我认为这就是开始时Close,Open序列的原因。
看起来很合理,谢谢你的例子。 – 2010-01-22 07:48:27