我在遺留代碼中使用帶有單向屬性= 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