[Gambas-user] Questions about the 'database' example

Tobias Boege taboege at ...626...
Fri Aug 31 12:48:55 CEST 2012


On Thu, 30 Aug 2012, rocko wrote:
> On Thu, 2012-08-30 at 18:37 -0700, John Spikowski wrote:
> > On Thu, 2012-08-30 at 18:15 -0700, rocko wrote:
> > > Been looking at the database example in Gambas 3.2.1.
> > > I believe it's the first one simply named 'Database'.
> > > I noticed on the Ftest.Form that the DataBrowser behaves differently.
> > > 
> > > For instance when you click on an record in the dataBrowser it populates
> > > a series of txt boxes with the data.
> > > Also if you click the [+] add record button it doesn't prompt you to add
> > > the record on the dataBrowser itself as is the default behavior, but 
> > > instead it clears the txt boxes and lets use them to enter a new record.
> > > Then you just simply click the save icon and it updates the dataBrowser.
> > > 
> > > I would love yo know how that was done.
> > > I looked thru the code but couldn't see anything that would  give me a
> > > clue.
> > > 
> > > Could some one point out the code that does this.
> > > I'm currently working on a similar project and that is just what I need.
> > > But I can't figure out how it's done.
> > 
> > If your database is bound to an object variable you may want to look for
> > that being nulled. By default all your form database fields would be
> > blanked (or default value) and ready for new entry repopulating the
> > object variable. I don't use Gambas enough to say this is how Gambas
> > deals with bond datasets.
> 
> I discovered I can use dataControls to bind to the fields in a table.
> But I think I have to use 2 dataSources, one for the dataBrowser the
> other for the dataControls.
> 
> The first dataSource i'm using contains the dataControls and the second
> dataSource along with the dataBrowser.
> However the dataControls are not displaying the fields they're set to 
> in the properties, the dataBrowser is working fine--so far.
> 
> If I click in a field in the dataBrowser, the dataControl it's bound 
> should display its data, but unfortunately for me it isn't.

The DataSource maintains a connection to a database. When there is a
DataBrowser within a DataSource control, the latter provides the former with
records to display, etc. When you select a record in the DataBrowser this
system automatically fills related DataControls. For this all to work, the
controls must be under the _same_ DataSource.

The thing with the Add-record button is that this belongs to DataBrowser so
you will find the code not in the example but in the gb.db.form component,
entirely written in Gambas - if you want to have a look.
When you click on that button, the DataSource is instructed to create a new
record, just as you would do it with Connection.Create(). Since that is
empty, your DataControls will be become empty, too.

Regards,
Tobi




More information about the User mailing list