Starting with TDBF lazarus / 16-Databases ---------------------------------------------------------------------- torbente · 2014-08-21 02:23 Hi everyone; Sorry if this is an old or easy question; i try to find it by myself around but since im just starting to work with DBs maybe i dont know what im exactly looking for. I created a TDBF with 2 fields (name and password) with my program, and i was able to edit it using mydbf studio. I dont know how i can access it from my program. I guess i need create a record, but im not sure how it will work. I include my code until now (this part is working perfect) Code: [Select]procedure tform1.InicializarDBF(); var   numerousuarios : integer; begin   memo1.lines.add(timetostr(now)+' Inicializando bases de datos');   usuarios.FilePathFull := 'C:\Users\eagle\Desktop\proyectos\server 1\';   usuarios.TableLevel := 7;   usuarios.TableName := 'clientes.dbf';   if fileexists('clientes.dbf') then      begin      memo1.lines.add('Base de datos usuarios existente');      usuarios.open;      numerousuarios := usuarios.RecordCount;      usuarios.close;      memo1.lines.add('Usuarios = '+inttostr(numerousuarios));      end   else      begin      With usuarios.FieldDefs do        begin        Add('Nombre', ftString, 16, True);        Add('password', ftString, 16, True);        end;      usuarios.Createtable;      usuarios.close;      end; end;    Thanks a lot. I checked a lot of info about DBFs but i was unable to make it work ---------------------------------------------------------------------- mangakissa · 2014-08-21 06:36 You need datacomponents and datasource to connect your database to your form. Just look at the demo of http://tdbf.sourceforge.net/ ---------------------------------------------------------------------- torbente · 2014-08-22 18:04 i already checked it, but im still lost. Are there any example easir to understand? Maybe something very simple. I neither was able to complie the given example. ---------------------------------------------------------------------- Never · 2014-08-22 18:21 i think this is pretty simple to start http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial http://sourceforge.net/projects/tdbf/files/TDbf%20documentation/ http://sourceforge.net/projects/lazarus- ccr/files/Demos%20and%20examples/Contacts%20Database%201.0/ ---------------------------------------------------------------------- mangakissa · 2014-08-24 13:00 a very very small demo ---------------------------------------------------------------------- miquelmatas · 2014-08-24 14:08 Thanks very much!!!!! ---------------------------------------------------------------------- torbente · 2014-08-24 15:48 That very small example gave me a good idea in a very easy way, but i still do not undertand how i can modify the database itself directly from the code. Let me see if i can explain better: Im creating a server, so to connect, the client needs to enter his login and password. The server must check the database to verify that information and allow the connection if it is correct. Also, if it is a new client, he could request to join the server, using a new login and password and the server be able to create a new record in the database to include this info. Basically i need do something like this (in the server): database.active; getusername; getpassword; // from client // all is done until here check_if_user_name_exists(); if_user_exists_check_password(); If_user_do_not_exists_create_new_one(); Also, i need to be able to change directly the info in case the client want chage his password in the future, for example. Thanks you all for your help. ---------------------------------------------------------------------- howardpc · 2014-08-24 16:15 You do realise that TDBF is not designed for database access over a network, and it does not offer true client/server at all? Nor does it give you robust database security. For more limited single-user desktop database applications TDBF offers quite a lot of functionality, and you can manipulate the filebound 'database' in code, as well as via the OI and form (or data module) designer. ---------------------------------------------------------------------- mangakissa · 2014-08-24 17:51 Try to understand what a database really is. QuoteA database is an organized collection of data. The data are typically organized to model aspects of reality in a way that supports processes requiring information. For example, modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies. (wikipedia) It can be a directory database on a pc /server with several files or a filebased database like Firebird, MS SQL, SQLBase. A application above will managed all your requirements to the database and back. Dbase is nothing more than a file with data (what howardpc says) and called a table. Quote from: torbentei still do not undertand how i can modify the database itself directly from the code But the demo is writing directly to the table. What you trying to do is fill a Tedit with a username and check this. TDBF (and other datasetcomponents) has a lot of properties and events. If you put in code dbf1. in the designer you get a lot of properties in a display. You can play with them. If you want to search in the table use .locate. If you want to see what .locate has found use .fieldbyname().AsString (for strings). This site will give you an example of locate. There are a lot of examples on the intetrnet. Mostly Delphi, but there are 100% compatible with Lazarus/FPC ---------------------------------------------------------------------- torbente · 2014-08-25 05:13 The server is already working, developed using indy for lazarus. It also already manages the login process using text files, but i decide try to change to dbf storage due to portability and to win some speed access. All i can sau now is that dbf is giving a lot more work than networking implementation EDIT: im trying to create a typed file in lazarus but i get an error; it is not suported now? i could do the job using this http://delphi.about.com/od/fileio/a/fileof_delphi.htm. ---------------------------------------------------------------------- mangakissa · 2014-08-25 07:01 What are you trying to accomplish? Only an login procedure or more with tables? Are there more desktops who wants to login? You can do it it with typed file, but if one pc is connected to the file another pc can't read it, because it's locked. ---------------------------------------------------------------------- torbente · 2014-08-25 07:22 Only the server will have access to the database. Looks like typed files can do the job, im working on it now. ---------------------------------------------------------------------- mangakissa · 2014-08-25 09:40 two examples to check the login: 1 with TDBF 2 with TBufdataset