Problems adding records to RB database 
Author Message
 Problems adding records to RB database

Hi,

Currently I'm looking into RB 2.1.2 by writing a small program which
keeps track of my cd's. A lot of it is running smoothly but I'm getting
Unhandled NILObjectException raised messages when I try to add a record
to the database. At the moment I'm stuck, I don't see what is going
wrong. Therefor your help is highly appreciated.

The database consists of one table (drager) and two fields (artiest en
titel). The database is valid, with an external program I was able to
add records and my program shows them in a listbox which is coupled to a
database query object. The project window of RB consists of a window,
the menu and the database. The database is located on my desktop and is
named muziek.rdb

The data is entered by means of two editfields, they also take care of
the validation.

To add a record I have written (in fact more or less copied) the
following code:

dim db as Database
dim rec as DatabaseRecord
rec = new DatabaseRecord
db = OpenREALDatabase(DesktopFolder.child("muziek.rdb"))
rec.column("artiest") = EditField1.Text
rec.column("titel") = EditField2.Text
db.InsertRecord("Drager", rec)
db.Close

When running the program trough the de{*filter*} I found that the program
crashes at the line db.InsertRecord("Drager", rec). That's something I
understand because - when checking the locals - db never gets any value,
it stays nil. The same applies to rec, it also never gets any value.

In the project window the database name muziek.rdb is truncated to
muziek, while watching the locals I get a popup menu for db which shows
nil and muziek.

At this point I'm lost, I checked the on-line documentation and found it
to be somewhat flawed. I am really looking forward to your input.

Regards, Ap

--
spam protected return adress



Thu, 03 Apr 2003 03:00:00 GMT  
 Problems adding records to RB database
Hi,

In trying to solve my problem with RB I described below I found that
when I isolated some code like this:

dim d as Database
dim c as databasecursor
dim fld as databasecursorfield
d = OpenREALDatabase(DesktopFolder.child("muziek.rdb"))
c = d.sqlselect("select * from drager")
while not c.eof
    fld = c.field("artiest")
    msgbox fld.stringvalue
    c.moveNext
    wend
d.Close

and put it in a stand-alone program as open event of the main and only
window it worked flawlessly. However when I pasted the very same code
into my program the Unhandled NILObjectException raised it's ugly head
once again. It only occurs when using the code from above, the program
itself runs without any problems except for accessing a database.

So the question is what does the rest of the program. Really nothing
special as you can see:

Window1.EnableMenuItems:
Sub EnableMenuItems()
  if TabPanel1.Value = 0 and EditField1.Enabled = False then
    RecordNieuw.Enabled = True
  end
  if TabPanel1.Value = 0 and EditField1.Enabled = True then
    RecordToevoegen.Enabled = True
    RecordAfbreken.Enabled = True
  end
  if TabPanel1.Value = 2 then
    FileAfdrukken.Enabled = True
  end
End Sub

Window1.Resized:
Sub Resized()
  TabPanel1.Height = Window1.Height - 18
  TabPanel1.Width = Window1.Width - 2
  ProgressBar1.Width = Window1.Width - 17
  ProgressBar1.Top = Window1.Height - 13
  EditField1.Width = Window1.Width - 96
  EditField2.Width = Window1.Width - 96
  ListBox1.Width = Window1.Width - 12
  ListBox1.Height = Window1.Height - 126
  EditField3.Width = Window1.Width - 109
  EditField3.Top = Window1.Height - 92
  PushButton1.Left = Window1.Width - 86
  PushButton1.Top = Window1.Height - 63
End Sub

Window1.EditField1.LostFocus:
Sub LostFocus()
  if Len(EditField1.Text) < 1 then
    EditField1.SetFocus
  end
End Sub

Window1.EditField1.TextChange:
Sub TextChange()
  ProgressBar1.Maximum = 65
   ProgressBar1.Value = Len(EditField1.Text)
End Sub

Window1.EditField1.GotFocus:
Sub GotFocus()
  ProgressBar1.Maximum = 64
  ProgressBar1.Value = Len(EditField1.Text)
End Sub

Window1.EditField2.LostFocus:
Sub LostFocus()
  if Len(EditField2.Text) < 1 then
    EditField2.SetFocus
  end
End Sub

Window1.EditField2.TextChange:
Sub TextChange()
  ProgressBar1.Maximum = 65
   ProgressBar1.Value = Len(EditField2.Text)
End Sub

Window1.EditField2.GotFocus:
Sub GotFocus()
  ProgressBar1.Maximum = 64
  ProgressBar1.Value = Len(EditField2.Text)
End Sub

Window1.PushButton1.Action:
Sub Action()
  DatabaseQuery1.sqlQuery = EditField3.Text
  DatabaseQuery1.runQuery
End Sub

MenuHandlers
RecordAfbreken // cancel adding record
EditField1.Enabled = False
EditField2.Enabled = False
EditField1.Text = ""
EditField2.Text = ""
ProgressBar1.Value = 0

RecordNieuw // adding new record
RecordNieuw.Enabled = False
ProgressBar1.Value = 0
EditField1.Enabled = True
EditField2.Enabled = True
EditField1.SetFocus

RecordToevoegen // put record in the database
dim db as Database
dim rec as DatabaseRecord
rec = new DatabaseRecord
db = OpenREALDatabase(DesktopFolder.child("muziek.rdb"))
rec.column("artiest") = EditField1.Text
rec.column("titel") = EditField2.Text
db.InsertRecord("Drager", rec)
db.Close

As I am only looking into RB - I am used to Delphi 4 from Borland - I am
wondering what the best way is how to solve this problem.  

Regards, Ap


Quote:
> Hi,

> Currently I'm looking into RB 2.1.2 by writing a small program which
> keeps track of my cd's. A lot of it is running smoothly but I'm getting
> Unhandled NILObjectException raised messages when I try to add a record
> to the database. At the moment I'm stuck, I don't see what is going
> wrong. Therefor your help is highly appreciated.

> The database consists of one table (drager) and two fields (artiest en
> titel). The database is valid, with an external program I was able to
> add records and my program shows them in a listbox which is coupled to a
> database query object. The project window of RB consists of a window,
> the menu and the database. The database is located on my desktop and is
> named muziek.rdb

> The data is entered by means of two editfields, they also take care of
> the validation.

> To add a record I have written (in fact more or less copied) the
> following code:

> dim db as Database
> dim rec as DatabaseRecord
> rec = new DatabaseRecord
> db = OpenREALDatabase(DesktopFolder.child("muziek.rdb"))
> rec.column("artiest") = EditField1.Text
> rec.column("titel") = EditField2.Text
> db.InsertRecord("Drager", rec)
> db.Close

> When running the program trough the de{*filter*} I found that the program
> crashes at the line db.InsertRecord("Drager", rec). That's something I
> understand because - when checking the locals - db never gets any value,
> it stays nil. The same applies to rec, it also never gets any value.

> In the project window the database name muziek.rdb is truncated to
> muziek, while watching the locals I get a popup menu for db which shows
> nil and muziek.

> At this point I'm lost, I checked the on-line documentation and found it
> to be somewhat flawed. I am really looking forward to your input.

> Regards, Ap

--
spam protected return adress


Fri, 04 Apr 2003 06:00:41 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. RB: row order by RB database

2. RB-Database Problem

3. Records Disappeared/Added to the prior Record No

4. Prime record fields on insert - Before adding auto incremented record

5. Add Child Record Within New Parent Record form.

6. Adding child records for a newly inserted parent record (CW2003)

7. Problem adding records with autoinc numbers without a window

8. CW2002.01 Record Add Problem.

9. Adding Records from Toolbar - a problem in C5E

10. Add record problem (ABC)

11. Problem with adding an auto-incremented record

12. problem adding records ?

 

 
Powered by phpBB® Forum Software