Home How To Increment Numbers in Calculated field of TQuery?
Reply: 2

How To Increment Numbers in Calculated field of TQuery?

Asad Alamdar
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#
Aqil Reply to 2017-11-13 21:16:00Z

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.

Asad Alamdar
3#
Asad Alamdar Reply to 2017-11-14 10:17:41Z

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.
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301513 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO