Recent

Author Topic: TDbf And FilePathFull  (Read 2938 times)

Fabius

  • Jr. Member
  • **
  • Posts: 59
TDbf And FilePathFull
« on: June 07, 2021, 07:21:09 pm »
Hello all

I have a problem with the DBF parameter

I can't seem to fill in the path

Either by form.activate
or
Dbf.beforeopen

Do you have any idea how to do it,

I am using the code below, but I have errors
satkoverflot
database

In short, it doesn't work

Ideas ?

please

Code: Pascal  [Select][+][-]
  1.    if Tdbfcompte.Active = True then
  2.    begin
  3.  
  4.    Tdbfcompte.Active := False;
  5.    end;
  6.  
  7.    if Tdbfcompte.Active = False then
  8.    begin
  9.     Tdbfcompte.Exclusive:= True;
  10.     Tdbfcompte.FilePathFull:= ExtractFilePath(Application.ExeName)+'\tables';
  11.     Tdbfcompte.FilePath:= ExtractFilePath(Application.ExeName)+'\tables';
  12.     Tdbfcompte.TableName:= 'comptes.dbf';
  13.     Tdbfcompte.Exclusive:= False;
  14.     Tdbfcompte.Active := True;
  15.     Tdbfcompte.First;
  16.    end;

[Edited to add code tags - please see How to use the Forums.] 
« Last Edit: June 08, 2021, 01:42:06 am by trev »

wp

  • Hero Member
  • *****
  • Posts: 11916

Fabius

  • Jr. Member
  • **
  • Posts: 59
Re: TDbf And FilePathFull
« Reply #2 on: June 07, 2021, 07:54:22 pm »
Hello

Thank you for the answer

I understood that ....
I show an example of what I did

but to distribute the EXE

the path changes with each installation

we must therefore tell the dbf, the path to opening the EXE

but it crashes


 Tdbfcompte.FilePathFull:= ExtractFilePath(Application.ExeName)+'\tables';


Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: TDbf And FilePathFull
« Reply #3 on: June 07, 2021, 09:15:09 pm »
This should work on both Windows and Linux:

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.FormCreate(Sender: TObject);  
  2. const
  3.   DataFileName = 'MyData';
  4. begin
  5. // ...
  6.   MyDbf.FilePathFull := ExtractFileDir(ParamStr(0));
  7.   MyDbf.TableName    := DataFileName + '.dbf';
  8. // ...
  9. end;

You can add sub directory at the end of FilePathFull if you want.


Note:
Using ParamStr(0) can cause problem on some OSes but I've been using the code above for years on Ubuntu for a small dbf note taking program I wrote and use it almost everyday, so far no problem. You should search the forum, there was a discussion for the better solution.
« Last Edit: June 07, 2021, 09:21:09 pm by Handoko »

Fabius

  • Jr. Member
  • **
  • Posts: 59
Re: TDbf And FilePathFull
« Reply #4 on: June 08, 2021, 10:17:24 am »
Hello All

Thank

compile , ok

but  if open , error

00000001000041B2 e859010000               callq  0x100004310 <fpc_pchar_length>

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TDbf And FilePathFull
« Reply #5 on: June 08, 2021, 10:42:49 am »
I am attaching a working example for you to compare. It creates the dbf at first start and adds some dummy data. The dbf will be in a subdirectory "data" of the application folder. Subsequent starts skip the creating step and open the now-existing dbf.

Fabius

  • Jr. Member
  • **
  • Posts: 59
Re: TDbf And FilePathFull
« Reply #6 on: June 08, 2021, 10:47:28 am »
I am attaching a working example for you to compare. It creates the dbf at first start and adds some dummy data. The dbf will be in a subdirectory "data" of the application folder. Subsequent starts skip the creating step and open the now-existing dbf.

thank you very much, I will retest

Fabius

  • Jr. Member
  • **
  • Posts: 59
Re: TDbf And FilePathFull
« Reply #7 on: June 10, 2021, 04:34:36 pm »


Form1.Xsaisie.FilePath:= Application.Location + 'tables\';   Very important the \ , lool

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TDbf And FilePathFull
« Reply #8 on: June 10, 2021, 04:38:03 pm »
Not important for the dbf per se, but important when something is done like I do: Application.FilePath + Application.TableName, I agree.

 

TinyPortal © 2005-2018