Subject |
Re: setting default value of fields |
From |
Heinz Kesting <Nobody@Nowhere.com> |
Date |
Sat, 6 Jul 2024 17:02:33 +0200 |
Newsgroups |
dbase.getting-started |
>>> I need to set default value of fields for a new created table
>>> programitically, If I use command below, it executes but when I open
>>> the same (mODI STRUC) and see the defaulf fields values still shows
>>> null.
>>>
>>> CREATE TABLE XYZ (code char(6) default "", qty numeric(6) default 0)
>>>
>>> Can anybody enligthen, if we can set default fields values
>>> programatically.
>>>
>>> Best Regards
>>> Mustansir
>>
>> Unfortunately CREATE TABLE is a localSQL command and, unlike "proper"
>> SQL, it doesn't support the DEFAULT option for fields.
>>
>> It should be possible to use functions from the BDE API (which is what
>> the table designer in the IDE does behind the scenes) to create a
>> table and set default values for fields but digging into the BDE API
>> is not for the fainthearted.
>>
>> As an alternative you can use the rowset's onSave() event handler to
>> force values into empty fields.
>>
>> function rowset_onSave()
>> if empty(this.fields['code'].value)
>> this.fields['code'].value := " "
>> endif
>> if empty(this.fields['qty'].value)
>> this.fields['qty'].value := 0
>> endif
>> return
>
> I'd suggest onAppend, actually ... then you can make it even simpler:
>
> function rowset_onAppend()
> this.fields['code'].value := ""
> this.fields['qty'].value := 0
> return
I would take this even one step further and use the canAppend event,
this would have the charm the desired default values would actually
appear when the user begins to append:
function rowset_canAppend()
this.fields['code'].value := ""
this.fields['qty'].value := 0
return true
Just my 2 cents ...
Kind regards, Heinz
|
|