Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-11

External SIGSEGV (random) when assigning TBookmark

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I don't use data aware controls too often, but as I'm updating a legacy application I have to use them.

Please take a look at this code. DataModule1.SQLQuery1 is a simple "select * from customers limit 10". What I want to accomplish is the refreshing of a DBGrid *without losing the focused row*, that's why I use a TBookmark.

To me, the code looks correct, but I'm getting a SIGSEGV while assigning the bookmark. I must add the error only happens the 2nd or 3rd time this method is called:

var
   lOldStatus: string;
   lBookmark : TBookmark;
begin
   lOldStatus := StatusBar1.Panels[1].Text;
   StatusBar1.Panels[1].Text := 'Updating...';
   lBookmark := DataModule1.SQLQuery1.Bookmark;
   DataModule1.SQLQuery1.DisableControls;
   DataModule1.SQLQuery1.Close;
   DataModule1.SQLQuery1.Open;
   DataModule1.SQLQuery1.EnableControls;
   DataModule1.SQLQuery1.Bookmark := lBookmark; <-- Random SIGSEGV
   StatusBar1.Panels[1].Text := lOldStatus;
end;
Leonardo M. Ram? Medical IT - Griensu S.A. Av. Col?n 636 - Piso 8 Of. A X5000EPT -- C?rdoba Tel.: +54(351)4246924 +54(351)4247788 +54(351)4247979 int. 19 Cel.: +54 9 (011) 40871877

Reply by email

Luca Olivetti
to Leonardo M. Ramé

El 01/11/15 a les 13:25, Leonardo M. Ram? ha escrit:

To me, the code looks correct, but I'm getting a SIGSEGV while assigning the bookmark. I must add the error only happens the 2nd or 3rd time this method is called:

I suppose that's because the bookmark is only valid while the query is opened, buy you close it between getting the bookmark and setting it.

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007

Reply by email

Virgo Pärna
to Luca Olivetti
Luca Olivetti wrote 9 lines
El 01/11/15 a les 13:25, Leonardo M. Ram? ha escrit: > To me, the code looks correct, but I'm getting a SIGSEGV while assigning > the bookmark. I must add the error only happens the 2nd or 3rd time this > method is called: I suppose that's because the bookmark is only valid while the query is opened, buy you close it between getting the bookmark and setting it.

Also: in my experience in Delphi closing with DisableControls active is a bad idea. I have seen cases, when components are still referencing old field instances.

Virgo P?rna

Reply by email

Luiz Americo Pereira Camara
to Luca Olivetti: El 01/11/15 a les 13:25, Leonardo M. Ram? ha escrit: I suppose that's because the…

2015-11-01 13:06 GMT-03:00 Luca Olivetti :

Show quoted text 11 lines
El 01/11/15 a les 13:25, Leonardo M. Ram? ha escrit: To me, the code looks correct, but I'm getting a SIGSEGV while assigning > the bookmark. I must add the error only happens the 2nd or 3rd time this > method is called: > I suppose that's because the bookmark is only valid while the query is opened, buy you close it between getting the bookmark and setting it.

Yes. In TBufDataset, the bookmark references the internal buffer memory. As soon dataset is closed, the memory may change

Luiz

Show quoted text 13 lines
Bye -- Luca Olivetti Wetron Automation Technology http://www.wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151102/54f14fc7/attachment.html>

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé: Hi, I don't use data aware controls too often, but as I'm updating a legacy application I…

El 01/11/15 a las 09:25, Leonardo M. Ram? escribi?:

Hi, I don't use data aware controls too often, but as I'm updating a legacy application I have to use them. ...

I finally solved this by getting the value of a primary key, then after TSQLQuery.refresh I do a locate for that key, works like a charm.

What I don't get is what's the purpouse of TBookmark, I thought it was made for solving the problem I had.

Leonardo.

Reply by email

Luca Olivetti
to Leonardo M. Ramé

El 03/11/15 a les 00:58, Leonardo M. Ram? ha escrit:

What I don't get is what's the purpouse of TBookmark, I thought it was made for solving the problem I had.

Yes, but only if you leave the dataset open.

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé: El 01/11/15 a las 09:25, Leonardo M. Ram? escribi?: I finally solved this by getting the…
Leonardo M. Ram? wrote 11 lines
El 01/11/15 a las 09:25, Leonardo M. Ram? escribi?: > Hi, I don't use data aware controls too often, but as I'm updating a > legacy application I have to use them. > ... I finally solved this by getting the value of a primary key, then after TSQLQuery.refresh I do a locate for that key, works like a charm. What I don't get is what's the purpouse of TBookmark, I thought it was made for solving the problem I had.

Bookmarks are only valid until the dataset closes. I will add this to the documentation.

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt

El 03/11/15 a las 04:40, Michael Van Canneyt escribi?:

Show quoted text 21 lines
On Mon, 2 Nov 2015, Leonardo M. Ram? wrote: > > El 01/11/15 a las 09:25, Leonardo M. Ram? escribi?: >> Hi, I don't use data aware controls too often, but as I'm updating a >> legacy application I have to use them. >> ... > > I finally solved this by getting the value of a primary key, then > after TSQLQuery.refresh I do a locate for that key, works like a charm. > > What I don't get is what's the purpouse of TBookmark, I thought it was > made for solving the problem I had. Bookmarks are only valid until the dataset closes. I will add this to the documentation. Michael.

Ok, but apart from Closing/Opening or Refresh, is there any other way to reload a dataset without closing it? TSqlQuery.Refresh also loses the Bookmark.

Regards,
Leonardo.

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
Leonardo M. Ram? wrote 26 lines
El 03/11/15 a las 04:40, Michael Van Canneyt escribi?: > > > On Mon, 2 Nov 2015, Leonardo M. Ram? wrote: > >> >> El 01/11/15 a las 09:25, Leonardo M. Ram? escribi?: >>> Hi, I don't use data aware controls too often, but as I'm updating a >>> legacy application I have to use them. >>> ... >> >> I finally solved this by getting the value of a primary key, then >> after TSQLQuery.refresh I do a locate for that key, works like a charm. >> >> What I don't get is what's the purpouse of TBookmark, I thought it was >> made for solving the problem I had. > > Bookmarks are only valid until the dataset closes. > I will add this to the documentation. > > Michael. > Ok, but apart from Closing/Opening or Refresh, is there any other way to reload a dataset without closing it? TSqlQuery.Refresh also loses the Bookmark.

No, there is not.

Michael.

Reply by email

Mark Morgan Lloyd
to Leonardo M. Ramé: El 03/11/15 a las 04:40, Michael Van Canneyt escribi?: Ok, but apart from Closing/Opening…
Leonardo M. Ram? wrote 26 lines
El 03/11/15 a las 04:40, Michael Van Canneyt escribi?: > > > On Mon, 2 Nov 2015, Leonardo M. Ram? wrote: > >> >> El 01/11/15 a las 09:25, Leonardo M. Ram? escribi?: >>> Hi, I don't use data aware controls too often, but as I'm updating a >>> legacy application I have to use them. >>> ... >> >> I finally solved this by getting the value of a primary key, then >> after TSQLQuery.refresh I do a locate for that key, works like a charm. >> >> What I don't get is what's the purpouse of TBookmark, I thought it was >> made for solving the problem I had. > > Bookmarks are only valid until the dataset closes. > I will add this to the documentation. > > Michael. > Ok, but apart from Closing/Opening or Refresh, is there any other way to reload a dataset without closing it? TSqlQuery.Refresh also loses the Bookmark.

Even if you could reload it, I'd have thought that the only valid way of positioning would be by locating against a column (preferably known to have an index). After all, the content of the table might have had gross changes due to the actions of other users, and potentially the layout might have changed.

I find myself moving away from data-aware controls and instead executing queries in a background thread, to try to avoid UI glitches while the backend's doing its stuff.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email