Forum > General

How can I connect a Database to Datasource1 ?

(1/4) > >>

Lupo:
Hi !
I'd like to use the database-components in lazarus. How do you connect a Datasource-Control with a database? Which database-format would you prefer?
Many thanks!
Lupo  :shock:

jesusr:
You need to compile some dataset components for example: TDbf, its simple and you dont need to install and setup a dbengine as MySQL or Firebird, but there are components for these too.

The steps to compile components vary depending if you are in linux or windows.

If you already compiled Tdbf component, then it's easy:

1. Drop a TDbf component
2. Drop a TDataSource Component
3. Drop some DataAware componentes: TDbEdit, TDbNavigator, TDbGrid (not very nice at the moment :(, all components need testing so bugs can be fixed ;) ), etc.
4. Wire everything
5. Open the dataset at runtime ( not a design time!). For ex:

   procedure Form1.FORMCREATE(sender: TObject)
    begin
      dbf1.Open;
    end;

Jesus Reyes A.

Anonymous:
Thanks a lot.
It seems to be difficult for a newbee like me. But I'll try it. Report later.

Lupo  :D

Anonymous:
Can you give an example of what you enter in the DataSet property of the TDataSource?

jesusr:

--- Quote from: "Anonymous" ---Can you give an example of what you enter in the DataSet property of the TDataSource?
--- End quote ---
Once you get a TDataSet component descendant compiled, for example TDBF with the above procedure (it will appear in the Data Access tab in the component palette), it's just a matter of droping a TDbf component on the form, it will be assigned a name for example tdbf1, then select the TDataSource component and in the Object inspector select the Dataset Property, this would be a combobox list. In this list there should be listed the tdbf1 component, select it and ready. they are now linked.

in the tdbf1 component remember to set the RunTimePath to the place you store the db files, and TableName to the name of the dbf file you want to open.

Then in the FormCreate Event, write something like

--- Code: ---
   tdbf1.Active := true.

--- End code ---

I think this is all to wire the non visual database components.

Navigation

[0] Message Index

[#] Next page

Go to full version