Recent

Author Topic: Is there any plan to modify TDataSource.Enabled property?  (Read 4950 times)

egsuh

  • Hero Member
  • *****
  • Posts: 834
If TDataSource.Enabled is set to false, then all the Data-aware controls linked to it should not show any content. Currently it does not seem to operate. Is there any plan to implement this?

GAN

  • Sr. Member
  • ****
  • Posts: 337
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #1 on: July 19, 2021, 10:42:43 pm »
I don't think so, to achieve that, you use the active property of the Tdataset that is linked to the TDataSource.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

https://searchlazarus.blogspot.com/

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3962
  • I like bugs.
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #2 on: July 20, 2021, 09:28:02 am »
Sounds like a bug though. Does it work in Delphi? A patch to implement it would be accepted surely.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

wp

  • Hero Member
  • *****
  • Posts: 8781
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #3 on: July 20, 2021, 10:28:36 am »
Justs checked with Delphi 7, XE2 and XE 10.3.3 (Community Edition): They behave as described in the first post - a dbgrid attached to a TDataSource becomes empty when DataSource.Enabled is switched to false, and this corresponds to Embarcadero documentation (http://docwiki.embarcadero.com/Libraries/Sydney/en/Data.DB.TDataSource.Enabled). The dataset, however, is not "closed" as I can see when I query the state of Dataset.Active periodically when the application is idle.

I wonder what this strange property could be good for... The Embarcadero help says also: "While an application can set Enabled to false to blank out data-aware controls during processing of multiple records, a better choice is to use the TDataSet EnableControls and DisableControls methods. Using these methods prevents the controls from blanking out during processing." This sounds as if this property is a poorly-thought left-over from the beginnings.
« Last Edit: July 20, 2021, 10:31:31 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Zoran

  • Hero Member
  • *****
  • Posts: 1675
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #4 on: July 20, 2021, 10:48:24 am »
I think that quite same behaviour can be achieved by setting DataSoruce.DataSet to nil. The dataset will not be closed, but the content of the connected db controls will disappear.

Then, if you want to "enable" the datasource again, you can set DataSource.DataSet back to the dataset.

egsuh

  • Hero Member
  • *****
  • Posts: 834
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #5 on: July 20, 2021, 01:03:46 pm »
I can achieve the same effect by setting datasource.dataset to nil, and to dataset. But this just looks little bit clumsy -- nothing else.

DataSet.Enable/disableControls --> In some cases, I might want to connect two datasources to one dataset, and keep one on and another one off.

Anyway there is a property but it does not operate as expected and documented.

https://www.freepascal.org/docs-html/current/fcl/db/tdatasource.enabled.html  says,

Quote
Enabled is by default set to True: the datasource instance communicates events from the dataset to components connected to the datasource, and vice versa: components can interact with the dataset. If the Enabled property is set to False then no events are communicated to connected components: it is as if the dataset property was set to Nil. Reversely, the components cannot interact with the dataset if the Enabled property is set to False.


BTW, TBufDataSet.Close seems to remove the database altogether. Can't I close it and then open again?

wp

  • Hero Member
  • *****
  • Posts: 8781
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #6 on: July 20, 2021, 01:29:35 pm »
I think that quite same behaviour can be achieved by setting DataSoruce.DataSet to nil. The dataset will not be closed, but the content of the connected db controls will disappear.
But this would break code imported from Delphi where Datasource.Dataset is <> nil in this case.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

LacaK

  • Hero Member
  • *****
  • Posts: 637
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #7 on: July 20, 2021, 02:42:16 pm »
Yes it seems, that Enabled property is not used.
I think that it can be implemented (something like in attached patch).

Can somebody fill bug report ...?
Or if somebody can confirm, that attached patch fixes problem then I can commit it ...
« Last Edit: July 20, 2021, 03:01:48 pm by LacaK »

devEric69

  • Hero Member
  • *****
  • Posts: 572
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #8 on: July 20, 2021, 05:17:23 pm »
For info., I've just tested @LacaK's patch on a single table (without master record and its details records pattern): assigning "datasource.Enabled:= false" de-illuminates its navigator (all its buttons become grey) as we should expect (tested with its IBX grid too, wich is not disabled, or emptied of data, as if the transactional connection was disabled, desactived; but this is not really abnormal with such transactionnal clients-server + cached updates layers).
« Last Edit: July 20, 2021, 07:58:49 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

LacaK

  • Hero Member
  • *****
  • Posts: 637
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #9 on: July 22, 2021, 10:13:42 am »
Patch was applied in rev.49630

devEric69

  • Hero Member
  • *****
  • Posts: 572
Re: Is there any plan to modify TDataSource.Enabled property?
« Reply #10 on: July 22, 2021, 11:14:11 am »
Thanks you very much @LacaK (the logic of your correction in the source code is simple and clear, for me anyway).
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

 

TinyPortal © 2005-2018