Forum > Beginners

Open/Load dbf files

(1/3) > >>

scons:
Ok, so I finished my first FPC/Lazarus application and now I'm so thrilled with the result that I want to try to write another application.

The aim is to write a simple app that open dbf files and write certain information from the database to a csv file, I don't need all the tables.

I jut started the form and my first issue i following: how can I open a dbf file at a certain location ? Can this be done with the "Open File" button ?

The few tutorials I have found are static databases. I want a button so I can choose the dbf file myself.

Any tips ?

Thanks

FTurtle:
Possibly it may be useful:
http://wiki.freepascal.org/Example:_TDbf_%28creating_table_and_indexes,_selecting_of_index%29

scons:
Thanks but I'm using this one already as my starting template.

But this example is also with a "fixed" database:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  CountriesFilename = 'countries.dbf'; 

howardpc:
Your button OnClick handler needs to be some variation on the following:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ... dialogs, ...; ... procedure TForm1.Button1Click(Sender: TObject);var  od: TOpenDialog;begin  od:=TOpenDialog.Create(nil);  try    od.Filter:='*.dbf|*.dbf';    od.Options:=[ofFileMustExist, ofPathMustExist]; // etc.    if od.Execute then      do_something_with_od.Filename    else ShowMessage('DBF file choice cancelled');  finally    od.Free;  end;end;

FTurtle:
This code works in that example:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// via TOpenDialog procedure TForm1.Button1Click(Sender: TObject);begin  OpenDialog1.Filter := 'dbf files|*.dbf';  // set in designer  OpenDialog1.Options := OpenDialog1.Options + [ofNoChangeDir]; // set in designer   if OpenDialog1.Execute then  begin    CountriesDbf.Active := False;    CountriesDbf.FilePathFull := ExtractFilePath(OpenDialog1.FileName);    CountriesDbf.TableName := ExtractFileName(OpenDialog1.FileName);    CountriesDbf.Active := True;  end;end; // via TFileNameEdit procedure TForm1.FileNameEdit1AcceptFileName(Sender: TObject; var Value: String  );begin  // set in designer: Filter:='dbf files|*.dbf'  // set in designer: DialogOptions + [ofNoChangeDir]   CountriesDbf.Active := False;  CountriesDbf.FilePathFull := ExtractFilePath(Value);  CountriesDbf.TableName := ExtractFileName(Value);  CountriesDbf.Active := True;end; 

Navigation

[0] Message Index

[#] Next page

Go to full version