Recent

Author Topic: Datasource not disabled  (Read 3058 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1296
Datasource not disabled
« on: August 28, 2018, 05:11:25 am »
Hi,
I linked a DBGrid to datasource, and which is to a dataset.
I set datasource.enabled to false, but the DBGrid still shows the content of the dataset.
Please confirm this.
Regards,

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Datasource not disabled
« Reply #1 on: August 28, 2018, 05:45:17 am »
You must close the DataSet if you want to empty the TDBgrid.
I think this behavior is fine.
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

egsuh

  • Hero Member
  • *****
  • Posts: 1296
Re: Datasource not disabled
« Reply #2 on: August 28, 2018, 06:30:06 am »

Quote
You must close the DataSet if you want to empty the TDBgrid.
I think this behavior is fine.

I don't think this is fine. When I change the content of a TDataset  programatically, if there are any linked TDataSource and TDataControls, this behavior slows down the operation by large, because every change in the TDataSet must be reflected in the TDataControls.

Just disabling TDataSource should prevent the content on the TDataControls from being refreshed. When the operation is finished, just enabling TDataSource would show the final result.

Of course I can do this by setting TDataSource.DataSet to nil and returning to the TDataSet, but the purpose of TDataSource.Enabled property is what I'm trying to do. 

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Datasource not disabled
« Reply #3 on: August 28, 2018, 06:47:36 am »
Quote
You must close the DataSet if you want to empty the TDBgrid.
I think this behavior is fine.

I don't think this is fine. When I change the content of a TDataset  programatically, if there are any linked TDataSource and TDataControls, this behavior slows down the operation by large, because every change in the TDataSet must be reflected in the TDataControls.

Just disabling TDataSource should prevent the content on the TDataControls from being refreshed. When the operation is finished, just enabling TDataSource would show the final result.

Of course I can do this by setting TDataSource.DataSet to nil and returning to the TDataSet, but the purpose of TDataSource.Enabled property is what I'm trying to do.
You should do this:
Code: Pascal  [Select][+][-]
  1.   SQLQuery.DisableControls;
  2.   ...
  3.   SQLQuery.EnableControls;

egsuh

  • Hero Member
  • *****
  • Posts: 1296
Re: Datasource not disabled
« Reply #4 on: August 28, 2018, 07:05:43 am »
Yes, I know there are many ways to achieve my purpose.
I'm saying that TDataSource.Enabled is designed to that purpose, and it should be implemented because other things may depend on the TDataSource as well, not only enabling/disabling controls. For example, I may write some codes within TDataSource.OnChange event, and sometimes I do not want these to be executed. Yes, I can write TDataSource.OnChange := nil, but TDataSource.Enabled must be enabled.


I tested following line with a small Delphi program, which exactly does what I expect.

Code: Pascal  [Select][+][-]
  1.   datasource1.Enabled := not datasource1.Enabled;

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Datasource not disabled
« Reply #5 on: August 28, 2018, 07:55:35 pm »
The help file agrees with you, a quick look on the source also shows that enabled is not used in any of the event processing code, report it on the bug tracker.
« Last Edit: August 28, 2018, 08:04:41 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018