#1 2017-03-04 07:14:58

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Confused by TSQLTable.RowFromID()

Hello Aranud,

The comment for the TSQLTable.RowFromID function:

    /// get the Row index corresponding to a specified ID
    // - return the Row number, from 1 to RowCount
    // - return RowCount (last row index) if this ID was not found or no
    // ID field is available
function RowFromID(aID: TID): integer;

I'm confused by this line:

return RowCount (last row index) if this ID was not found.

How to distinguish the situation where the ID value is found in the last row (which equals to RowCount), and "if this ID was not found" quoted above?

Thanks.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2017-03-04 11:39:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Confused by TSQLTable.RowFromID()

It works as designed.
Purpose of this method was to select the current row in a grid.
This is the meaning of "Row" here: we are dealing about UI, not
If there is no matching ID, the latest row is selected.

I've added the aNotFoundMinusOne optional parameter to TSQLTable.RowFromID to return -1 if aID is not found.
See https://synopse.info/fossil/info/7382477aa058b41c

Offline

#3 2017-03-05 06:16:45

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: Confused by TSQLTable.RowFromID()

Thanks ab.

I was using it to locate the row index by ID value.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB