Felipe Monteiro de Carvalho wrote:
Hi,
I am trying to use sqlite package to connect to a sqlite database and
create a simple gui that interacts with it.
I followed the steps on the tutorial and created a sqlite database
file rightclicking the TSqliteDataset component. I also added some
data to the database using the command line tool that comes with sqlite.
Now I have 5 components on my form: SqliteDataset, a Datasource, a
DBGrid, DBNavigator and a DBEdit.
First problem: I connected the datasource to the dataset, and the DB
components to the datasource, but when I try to se a field for the
DBEdit I see no fields available to select. If I just type the field
name by hand it will give me a "Field not Found". I tryed to connect
the field coding something like:
DBEdit.Field.Assign(SqliteDataset.FieldByName('Nome')); but this
didn't work.
For the field list be show in DBEdit.DataField property is necessary to
set the TDataset.Active property to true. Anyway dont worry about the
message saying "no Field Found". Ignore it and it will work if you set
the a correct field name.
Second problem: On the DBGrid I can see the dummy data I entered, but
if I try to write new data, as soon as I leave the newly created
record it vanishes! It will only write if I click the Post button on
the DBNavigator. Is there a way to make it always write?
This is the way TDataset works. If a record is not posted then it can
be cancelled (maybe DBGrid is calling cancel in this case).
A simple way to add a record is to do a procedure like:
ASlite.Append;
ASqlite.Post;
and associate with a button OnClick event.
Be aware that data will not be saved to database. If you want this then
call ApplyUpdates (see conditions in wiki to ApplyUpdates work) or set
SaveOnClose to true.
I am opening and closing the dataset on OnCreate and OnDestroy,
because I cannot find out how to activate the dataset at design-time
to select the fields:
Active:=True; ?
procedure TjanelaPrincipal.FormCreate(Sender: TObject);
begin
SqliteDataset.Open;
// DBNome.Field.Assign(SqliteDataset.FieldByName('Nome'));
end;
procedure TjanelaPrincipal.FormDestroy(Sender: TObject);
begin
SqliteDataset.Close;
end;
I am using Mandriva Linux 2005, the latest Lazarus (svn) and my sqlite
package is: libsqlite0-2.8.16-1mdk
BTW: Are you brazilian?
Luiz
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives