Recent

Author Topic: Starting with TDBF  (Read 6660 times)

torbente

  • Full Member
  • ***
  • Posts: 229
Starting with TDBF
« on: August 21, 2014, 04:23:56 am »
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
« Last Edit: August 21, 2014, 06:10:31 am by marcov »

mangakissa

  • Hero Member
  • *****
  • Posts: 1096
Re: Starting with TDBF
« Reply #1 on: August 21, 2014, 08:36:21 am »
You need datacomponents and datasource to connect your database to your form. Just look at the demo of http://tdbf.sourceforge.net/





Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

torbente

  • Full Member
  • ***
  • Posts: 229
Re: Starting with TDBF
« Reply #2 on: August 22, 2014, 08:04:45 pm »
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

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

mangakissa

  • Hero Member
  • *****
  • Posts: 1096
Re: Starting with TDBF
« Reply #4 on: August 24, 2014, 03:00:07 pm »
a very very small demo  :D
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

miquelmatas

  • Jr. Member
  • **
  • Posts: 98
  • Beginner forever.
Re: Starting with TDBF
« Reply #5 on: August 24, 2014, 04:08:46 pm »
Thanks very much!!!!!
--
Cheers.
Miquel.

torbente

  • Full Member
  • ***
  • Posts: 229
Re: Starting with TDBF
« Reply #6 on: August 24, 2014, 05:48:40 pm »
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.

« Last Edit: August 24, 2014, 05:56:48 pm by torbente »

howardpc

  • Hero Member
  • *****
  • Posts: 3545
Re: Starting with TDBF
« Reply #7 on: August 24, 2014, 06:15:31 pm »
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

  • Hero Member
  • *****
  • Posts: 1096
Re: Starting with TDBF
« Reply #8 on: August 24, 2014, 07:51:17 pm »
Try to understand what a database really is.
Quote
A 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: torbente
i 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(<fieldname>).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
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

torbente

  • Full Member
  • ***
  • Posts: 229
Re: Starting with TDBF
« Reply #9 on: August 25, 2014, 07:13:47 am »
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.
« Last Edit: August 25, 2014, 08:54:29 am by torbente »

mangakissa

  • Hero Member
  • *****
  • Posts: 1096
Re: Starting with TDBF
« Reply #10 on: August 25, 2014, 09:01:31 am »
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.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

torbente

  • Full Member
  • ***
  • Posts: 229
Re: Starting with TDBF
« Reply #11 on: August 25, 2014, 09:22:44 am »
Only the server will have access to the database. Looks like typed files can do the job, im working on it now.

mangakissa

  • Hero Member
  • *****
  • Posts: 1096
Re: Starting with TDBF
« Reply #12 on: August 25, 2014, 11:40:21 am »
two examples to check the login:
1 with TDBF
2 with TBufdataset
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018