Recent

Author Topic: DBGrid question (SOLVED)  (Read 4795 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
DBGrid question (SOLVED)
« on: January 05, 2012, 10:08:54 am »
I have a DBGrid attached to a datasource and I want to change the data that I see but I will not allow the user to create new lines. How can I do?
« Last Edit: January 09, 2012, 05:07:55 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: DBGrid question
« Reply #1 on: January 05, 2012, 10:27:57 am »
Set dgDisableInsert to true in TDBGrid.Options

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: DBGrid question
« Reply #2 on: January 05, 2012, 11:03:30 am »
Thank you  :)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: DBGrid question
« Reply #3 on: January 05, 2012, 11:08:19 am »
Don't exist this propriety!  :o
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: DBGrid question
« Reply #4 on: January 05, 2012, 11:25:20 am »
Don't exist this propriety!  :o
lazarus 0.9.31 svn 34537. Don't know when it was introduced.

Another approach would be to use the datasources OnStateChange event, detect if state = dsInsert and then Cancel.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: DBGrid question
« Reply #5 on: January 05, 2012, 11:53:53 am »
Ok thank you
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: DBGrid question
« Reply #6 on: January 09, 2012, 04:41:27 pm »
Don't exist this propriety!  :o
lazarus 0.9.31 svn 34537. Don't know when it was introduced.

Another approach would be to use the datasources OnStateChange event, detect if state = dsInsert and then Cancel.

Error:

unit_principale.pas(805,15) Error: Identifier not found "state"
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: DBGrid question
« Reply #7 on: January 09, 2012, 05:07:41 pm »
I solved with this code

Abort;

into BeforeInsert procedure!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: DBGrid question
« Reply #8 on: January 09, 2012, 07:13:32 pm »
Another approach would be to use the datasources OnStateChange event, detect if state = dsInsert and then Cancel.

Error:

unit_principale.pas(805,15) Error: Identifier not found "state"

State is a property of the datasource. So the full code would be:
Code: [Select]
if Datasource.State=dsInsert then Datasource.DataSet.Cancel;

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: DBGrid question (SOLVED)
« Reply #9 on: January 09, 2012, 08:11:58 pm »
I solved with this code

Abort;

into BeforeInsert procedure!
Hmm. And Ctrl-alt-del to close the form  :D

Abort raises a silent exception and you never know exactly in what state you leave the program. Code is triggered here by an event (key or mouse events) and aborted with an exception. I checked the database code and I think in this case you are lucky. I haven't checked all possible cases though.


 


 

TinyPortal © 2005-2018