FNCGrid problem/bug?

I have a problem with the FNCGrid.
I have a grid attached to a Query and it shows me the customer numbers and names.
When I doubleclick a row (selection mode is smDisjunctRow) I want to get the customernumber and do something with it.
The grid shows me 5 rows (records) and within this 5 rows this works fine.
But when I scroll down to the 6th record I'm getting the customernumber of the 7th record and scrolling down further I get accessviolations.

The code I am using to retrieve the customer numbers is

RecID:= TMSFNCGrid_Adres.GetCellObject(MakeCell(0,TMSFNCGrid_Adres.FocusedCell.Row)).Text;

OR
RecID:= TMSFNCGrid_Adres.GetCellObject(MakeCell(0,TMSFNCGrid_Adres.SelectedRow[0])).Text; }

this makes no difference

Even tried:
TMSFNCGrid_Adres.DisplToRealRow(TMSFNCGrid_Adres.FocusedCell.Row);
OR
TMSFNCGrid_Adres.RealToDisplRow(TMSFNCGrid_Adres.FocusedCell.Row);

Before retreiving the number, makes no difference at all.
I'm using the latest version of the UI Pack
Regards
Anske

GetCellObject returns an object. Please check if the object it returns is Assigned before accessing it. If you want to retrieve the text you'll need to map it directly on the dataset. the grid is not keeping data in memory when attached to a dataset. A sample on how to save/restore the active record can be found here:

Okay I'm gone try that but what I don't understand is the following;

My procedure is

procedure TFrm_ASRegister.TMSFNCGrid_AdresKeyDown(Sender: TObject;
var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
if (Key = vkReturn) then
begin
if (TMSFNCGrid_Adres.RowCount > 0) then
begin
RecID:= TMSFNCGrid_Adres.GetCellObject(MakeCell(0,TMSFNCGrid_Adres.FocusedCell.Row)).Text;
..
do something with the recid
..
end;
end;
end;

Value Resulting RecID scrolling down and press enter Resulting RecID moving up
40000 40000 40000
50034 50034 50076
50067 50067 50149
50147 50147 50292
50149 50149 50307
50205 50292 50311
50292 AV AV
50294 AV AV

Like I already explained, the GetCellObject returns an object. Please check the object before accessing it. Also, the grid only loads the data for the visible rows, that's the reason why you are getting access violations.

If the grid only loads data for the visible rows how is it then possible that when scrolling DOWN from 50149 to 50205 the resulting value is 50292 that row was not visible jet and when scrolling UP from 50292 to 50205 the result is 50311 that one hasn't been visible at all.
That kind of behaviour I don't understand.

Otherwise the example you send helped me to figure out how I could resolve my problem.
Thank you for that.

1 Like