OnCalcFields and RecNo

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
mr.amit.g

OnCalcFields and RecNo

Post 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?
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post 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 :)
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post 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.
subnike
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 02.02.2007, 09:09

Post 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;
Post Reply