Page 1 of 1
OnCalcFields and RecNo
Posted: 20.02.2006, 14:04
by mr.amit.g
Hi,
I'm trying ZeosLib...
I'm doing this in my demo application...
Code: Select all
procedure dmDatabase.MessagesCalcFields(DataSet: TDataSet);
begin
MessagesNO.asInteger := Messages.RecNo;
end;
MessagesNO is a Calculated field which I'm using for giving no to the messages.
It gives strange results in DBGrid...
This works with IBX...
What is going wrong?
Posted: 20.02.2006, 15:56
by gto
hum... maybe the RecNo isn't updated when calcfields is executed
An idea is to deal with some database field (something like add another field called "code", "index"..) or even access the RecNo property directy, as you don't make any changes to it
Posted: 22.02.2006, 14:49
by zippo
Have you traced?
Add a line like this
ShowMessage(IntToStr(Messages.RecNo));
But my suggestion is that you use the operation once, not on every calculation. Just to be sure. It' ssomehow innatural form me to calculate the current row basing onto previous rows.. (BTW: Some people say thet RecNo is very slow) If I were you I would create something like this.
AfterOpen event
Code: Select all
begin
DataSet.DisableControls;
while not DataSet.Eof do begin
DataSet.Edit;
DataSet.FieldByName('MessagesNo').AsInteger := DataSet.RecNo;
DataSet.Next;
end;
DataSet.DisableControls;
It's executed just once, so should be faster. ah, and MessagesNO shouldn't be calculated anymore.
Posted: 02.02.2007, 09:37
by subnike
I find the code in ZAbstractRODataset.pas line:1678
Code: Select all
function TZAbstractRODataset.GetRecNo: Longint;
begin
if Active then
UpdateCursorPos;
Result := CurrentRow;
end;
Why use UpdateCursorPos?
When I obtain RecNO also setting up its RecNO in the meantime, such as whether have a little aoddiness.
And I remark
Code: Select all
function TZAbstractRODataset.GetRecNo: Longint;
begin
// if Active then
// UpdateCursorPos;
Result := CurrentRow;
end;