[Gambas-user] Database example

Ron_1st ronstk at ...239...
Mon Jun 15 03:14:25 CEST 2009


On Sunday 14 June 2009, charlesg wrote:
> 
> Hi,
> 
> I have extracted what I need from the database example. I can even get it to
> do exactly what I want. But, in truth, I do not understand how it works
> exactly.
> '===================================================
> ' FMain.class
> PUBLIC $hConnLocl AS NEW Connection
> PUBLIC $resData AS Result
> '--------------------------------------------------------
> PUBLIC SUB Form_Open()
>   WITH $hConnLocl
>     .type = "sqlite3"
>     .Name = "/home/charles/sqlite3/locl.sqlite"
>   END WITH 
>   $hConnLocl.Open()
>   $resData = $hConnLocl.Exec("select * from hist")
> END
> '---------------------------------------------------------
> PUBLIC SUB btnRun_Click()
>   DIM hForm AS FRequest
>    
>   hForm = NEW FRequest($hConnLocl, $resData)
>   hForm.show
> END
> '===================================================
> ' FRequest.class  
> PRIVATE $hConnlocl AS Connection
> PRIVATE $rData AS Result
> '---------------------------------------------------------
> PUBLIC SUB _new(hConnlocl AS Connection, rData AS Result)
>   DIM hField AS ResultField
>   DIM iInd AS Integer
>   
>   $hConnlocl = hConnlocl
>   $rData = rData
>   tbvData.Rows.count = 0
>   tbvData.Columns.count = $rData.Fields.Count
>   
>   FOR EACH hField IN $rData.Fields
>     WITH hField
>       tbvData.Columns[iInd].text = .Name
>       tbvData.Columns[iInd].width = 60
>     END WITH 
>     INC iInd
>   NEXT
>   tbvData.Rows.Count = $rData.Count
> END
> '---------------------------------------------------------
> PUBLIC SUB tbvData_Data(Row AS Integer, Column AS Integer)
>   $rData.MoveTo(row)
>   tbvData.Data.text = Str($rData[tbvData.Columns[column].text])
> END
> '===================================================
> 
> My lack of understanding hinges around:
> 1.	hForm = NEW FRequest($hConnLocl, $resData)
> 2.	$hConnlocl = hConnlocl
>   	$rData = rData
> 3.	The help says _data is called when the tableview 'needs data'. At what
> point in the code does it need this data?
> 
> Any fog elimination welcomed.
> 
> rgds
> 

For answer on the _Data event.
Asume you have a database of 10000 records and 200 columns then
it wil not fit on your form with the tableview.
Also it is not importand to fill the cells you can't see.
However using the scrollbars you can navigate over the records.
At that moment when there are new cells comming visible the _Data
event happnes and ask for the data to show in the cell.
Cells that goes hidden drops there content to save memory space in
the Xservers memory pool.

When other forms/windows overlay your table view they also do not
ask cell data. You can't see it so why asking and use memory :)

Second, by only asking with _Data event for the visible cells makes
your tableview shows quick the actual visible info. 
Think of the time to fill 10000 row times 200 collumns 
where only i.e. 4rows and 5 columns are visible.

 

Best regards,

Ron_1st

-- 

111.111111 x 111.111111 = 12345.678987654321






More information about the User mailing list