Well, I still think it should work. I don't see a problem in your code so the problem must be in code we haven't seen yet.
However, I do think you are making your life more difficult that it need be. First, I suggest going to my website and reading the artciles about building database objects.
http://ourworld.compuserve.com/homepage ... rogram.htmI will try to summarize them here.
Make a
subclass of TDatabase that contains methods add() and edit(). This makes your code much easier and also allows you to use polymorphism later. In this case you are also going to need an isUnique() method (although I wonder why you don't just generate a unique ID automatically).
- Code: Select all Expand view
class TCustomer from TDatabase
data lAdd hidden
method add
method edit
method isUnique
end
method add()
lAdd:=.t.
::edit()
lAdd:=.f.
::load()
return self
method edit()
local oDlg
if ::lAdd
::blank()
endif
define dialog oDlg
...
redefine get oGet ::nomtracod valid isUnique( oGet:varGet() )
redefine button ID_OK action ::save()
activate dialog oDlg
return self
method isUnique(cNomtracod)
local nRecno:=::recno()
local lSuccess:=.f.
::lBuffer:=.f.
::seek(cNomtracod)
if ::found()
msgInfo(...)
else
::lSuccess:=.t.
endif
::goto(::nRecno)
::lBuffer:=.t.
return lSuccess
That is the basics of it. Now you can do:
oCustomer:edit()
or,
oCustomer:add()
If you are trying to get the user to input a unique primary-key value, then I would not. For the user this is a real pain--it's like typing into a black hole. They don't know what to type and there is nothing to help them but a rude error message. I would generate sequential keys automatically.
If you are trying to get the user to type in a valid pre-existing code, then I would use a combobox instead. Better, with DBCombo, you can provide a list of descriptions and automatically get the corresponding code. This way the user doesn't even have to know the codes. The lastest version of DBCombo also has a dynamic search so the user can type in a few keystrokes to get the first match.
Perhaps something in here helps...
Regards,
James