Home How To Increment Numbers in Calculated field of TQuery?

# How To Increment Numbers in Calculated field of TQuery?

1#
Asad Alamdar Published in 2017-11-13 12:32:06Z
 I Have TQuery With Calculated Field N. How To Increment Numbers in the example (N starts with 5): I tried this but Nothing: procedure TForm1.Query1CalcFields(DataSet: TDataSet); var i:integer; begin i := strtoint(edit2.Text); Query1['N'] := inttostr(i+1); end;  result: N 2 2 2 2 . .  Note: Foxpro database ,i use BDE to connect with ,It does not have to be a calculated field ,i want the Incremented value to use it in print of quickreport like a single reference for each Page (not pagenumber).
Aqil
2#
 This is a simple way that I test it: 1- declare a global variable for saving auto number 2- Set it in FormShow to 5 3- In OnCalcFields assign global variable to the new field 4- increment global variable Notes: Do not use TEdit or any thing for show the result of calculate field, because it will just show the first result. but all the result will save in table or query correctly. Codes Global Variable: var Form1: TForm1; i : Integer;  Form Show: procedure TForm1.FormShow(Sender: TObject); begin i := 5; end;  Calc Filed: procedure TForm1.adoqry1CalcFields(DataSet: TDataSet); begin adoqry1['n'] := i; //OR adoqry1N.AsInteger := i; //OR adoqry1.FieldByName('n').AsInteger := i; i := i + 1; end;  At the end, I test it with ADOQuery.
 I Found This Solution With The Help Of @kobik In Printing Of TQRLabel I Add This Code And No Needed To The Calculated Field Or Other Varible: procedure TForm1.QRLabel1Print(sender: TObject; var Value: string); begin value:=inttostr(Query1.RecNo+strtoint(edit2.Text)-1); end;  The Tedit To Costume The Start Number At Runtime.