1

I Have TQuery With Calculated Field N.
How To Increment Numbers in the example (N starts with 5):

enter image description here

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).

Asad Alamdar
  • 158
  • 8

2 Answers2

1

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.
Asad Alamdar
  • 158
  • 8
0

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.

Aqil
  • 360
  • 2
  • 16
  • 1
    This won't work when scrolling the dataset. I posted a similar answer but deleted it after I tested it. – kobik Nov 14 '17 at 06:07
  • it work for me,But this method is not concise ,Simply put this code when CalcFields : `Query1.RecNo+strtoint(edit2.Text)-1` ,the tedit to costume the start number – Asad Alamdar Nov 14 '17 at 07:49
  • and for more concise in printing TQRLabel i add this code and no needed to the calculated field : `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 in runtime. – Asad Alamdar Nov 14 '17 at 07:56
  • I think it is better you explain your question more. – Aqil Nov 14 '17 at 13:47