Recent

Author Topic: How changing path DBF file at runtime  (Read 2270 times)

MVD

  • New Member
  • *
  • Posts: 23
How changing path DBF file at runtime
« on: September 22, 2017, 10:34:09 pm »
Hi,
I wonder if it is possible to change the path from my DBF files at runtime.
Now the path is hardcoded in the visual component, but if someone else will use the program or if the location of the files changed, I would have the possibility to change the path at runtime. I was looking to the different components but I wonder witch can give the full path I selected as return value.

Thanks!

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: How changing path DBF file at runtime
« Reply #1 on: September 22, 2017, 11:02:56 pm »
Need a little more info to give a definitive answer - like what database components you are using.
It is certainly possible to change the paths while the application is running, just remember to close any active database components first, and re-open them after you set the path.
If necessary you could even use the TOpenDialog to allow your users to select files from the local machine, using file type filters you provide.
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: How changing path DBF file at runtime
« Reply #2 on: September 23, 2017, 12:29:51 am »
I always have the (SQLite) database in the folder where the program was installed and at program start do something like this:
Code: Pascal  [Select][+][-]
  1.        
  2. // Open database
  3.        DataModule1.DbConnection.Connected := False;
  4.        DataModule1.DbConnection.DatabaseName := SysUtils.ExtractFilePath(ParamStr(0)) + 'DatabaseName.db';
  5.        DataModule1.DbConnection.Connected := True;
  6.  
  7.        if DataModule1.DbConnection.Transaction.Active = False
  8.        then DataModule1.DbConnection.Transaction.StartTransaction;
  9.  

In the same way you can assign any path you like to your database.
Maybe this idea helps you.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: How changing path DBF file at runtime
« Reply #3 on: September 23, 2017, 08:41:09 am »
Code: [Select]
if it depends on TDBF, try this:
[code = pascal]
MyPath := <your location to dbf file>
<your tdbfname>.FilePathFull := MyPath; //Directory where all .dbf files will be stored
Look at http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018