ado: set default field values

hi all,
i have a table with some default values
for example "IsMember" set to False.

now, when i insert a NEW record (insert mode) in my form and uses TDBCheckBox
the DBCheckBox is grayed (and checked) as if the initial value is NULL.
how can i make the DBCheckBox to set the default values from the DB, so it is marked as the default?

hope my queston is clear.
LVL 1
morgantopAsked:
Who is Participating?
 
kretzschmarConnect With a Mentor Commented:
well, a trick

type
  TCrackDataSet = Class(TDataSet);

procedure TForm1.Button1Click(Sender: TObject);
begin
  TCrackDataSet(Table1).SetModified(False);
end;

just use it in the afterInsert-event,
to reset the modified flag to false

hope it works for you

meikl ;-)
0
 
kretzschmarCommented:
usual dafaults are only set
when the record is being about
to be inserted into the db and
the user did not providing a value
or a explicit NULL -> on post

usual most frontends (also delphi)
are giving an explicite NULL to the DB,
if the user didn't enter a value,
but you can give at TField-Level
a DefaultExpression -> property,
(on some databases this default
is read out from the db automatically,
guessing not with ADO (never tested))
which is applied on post.

if you want the fields prepared
with a defaul-value, then u have
to do it byself, using the
afterInsert-event of the dataset.

meikl ;-)
0
 
morgantopAuthor Commented:
hi kretzschmar,

>if you want the fields prepared
>with a defaul-value, then u have
>to do it byself, using the
>afterInsert-event of the dataset.

problem is that i'm checking the dataset.Modified flag.
if i change dataset on afterInsert event, Modified is set to true.
is there a way to clear the Modified flag, without posting?
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
kretzschmarCommented:
>is there a way to clear the Modified flag,
>without posting?

nope, its a readonly-property,
how or why do you check this flag?
0
 
morgantopAuthor Commented:
when user addes new record,
i open a modal form (with db-awrae controls bound to a dataset) set dataset.Append and the user fills the info.

if he press 'cancel' button i do dataset.Cancel
if he press 'ok' i check if the dataset.Modifyed only then make dataset.Post (and other sql inserts)

this works well but my DBCheckBox's are allways checked+grayed (the initial problem)
i dont remember having such "problem" with paradox.

you see my problem?

thanks.
0
 
morgantopAuthor Commented:
briliant as usual :)
0
All Courses

From novice to tech pro — start learning today.