#1 2016-05-02 23:50:13

igors233
Member
Registered: 2012-09-10
Posts: 234

AV in TSQLTable.GetString/StrLen and TSQLTableToGrid

In some cases there is AV in StrLen (StrLenSSE2) when it's called with invalid pointer (usually it's $1).
That occures when StrLen is called from TSQLTable.GetString (which is called from ExpandAsString),
That pointer is returned with U := Get(Row,Field).

This happens all the time (to me at least), from debugger but I don't know how to create a test case since in runtime it happens only sometimes.

Here are more details, data is created with TSQLRecord.CreateAndFillPrepare (few rows is returned), and those data is shown with TSQLTableToGrid and draw grid.
When new filter is applied (that doesn't return records) to same SQLRecord with FillPrepare, it happens that somehow (I don't understand how exactly) draw grid paint cycle is invoked before FillPrepare finishes which puts data in inconsistent state so this AV occures.

This could be fixed if TSQLTableToGrid doesn't invoke paint cycle or if it's unlinked from SQLTable while table is being updated (in FillPrepare). AFAICS this isn't possible from within TSQLTableToGrid, i can only nil OnDrawCell event and restore it later, but I think some new method (like TDataSet.DisableControls) should be introduced.

Also TSQLTableToGrid.Destroy, tries to release associated SQLTable
with FreeAndNil(fTable), but it shouldn't do so since it doesn't necessarily own that table.

Offline

#2 2016-05-03 10:16:01

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

Re: AV in TSQLTable.GetString/StrLen and TSQLTableToGrid

A lot of things here... difficult to find out all the items...

If you disable StrLenSSE2 use, does it work without A/V?
I'm not sure it is due to StrLenSSE2, but probably because your TSQLTableJSON instance is released, in your code, before use in TSQLTableToGrid.
If you use CreateAndFillPrepare, the internal TSQLTableJSON is owned by the TSQLRecord instance, so I guess this is why your A/V occurs later on in the grid.
You should use a dedicated TSQLTableJSON instance, or plain JSON, as in the samples.

Offline

#3 2016-05-03 16:47:09

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: AV in TSQLTable.GetString/StrLen and TSQLTableToGrid

Thanks for the help.

> If you disable StrLenSSE2 use, does it work without A/V?

No, it fails in UnCamelCase then.

> I'm not sure it is due to StrLenSSE2, but probably because your TSQLTableJSON instance is released, in your code,
> before use in TSQLTableToGrid.

You're right, within FillPrepare, FillClose is called that released TSQLTable.

> If you use CreateAndFillPrepare, the internal TSQLTableJSON is owned by the TSQLRecord instance,
> so I guess this is why your A/V occurs later on in the grid.
> You should use a dedicated TSQLTableJSON instance, or plain JSON, as in the samples.

So I cannot use SQLRecord.FillTable with TSQLTableToGrid? I have to create a separate TSQLTableJSON instance and then copy values from SQLRecord.FillTable to it?
What is the prefered/fastest way to copy all records from SQLRecord.FillTable to TSQLTableJSON?

Can you please update documentation for TSQLTableToGrid, and emphasize that it must be used with a dedicated TSQLTable/TSQLTableJSON instance.
Also I would suggest to include TSQLTableToGrid usage in pair with SQLRecord.CreateAndFillPrepare or FillPrepare, right now none of samples handle directly displaying data from TSQLRecord.

Last edited by igors233 (2016-05-03 16:48:02)

Offline

Board footer

Powered by FluxBB