You may want to look at the TDBF component. I think the package is called lazdbf or dbflaz.
Michael. On Tue, 15 Jun 2010, Peter E Williams wrote:
Hi All, I really need to know what is the Dbase3/4 unit for Lazarus/Free Pascal and where is the sample project for manipulating them. I found it somewhere on the lazarus website but don't know where. I hope that it is okay for me to post some of my code which uses the XBase1 unit in Delphi 5 Enterprise which I am porting to my Hexxpawn8 game (which is cross platform open source). I use Dbase3/4+ files to store board patterns for my game which is sort of a cross between the pawns in Chess and checkers, using AI logic against the computer. (I chose Dbase format because it was the single most common database file format at the time.) What is the replacement unit for XBase1 for using Dbase3/4 files, and the functions/procedures etc to replace these calls to XBase1 ? How do I do the following: // declaring a Dbase file -- TXBase (what is the equivalent in Lazarus?) // how do I copy a blank.dfg file to hex8.bdf (Copyfile) ??? // I need to Goto to the Bottom of File (HexxData.GotoBOF;) // I need to call a function GetFieldByName passing a string as the field name and comparing it with a character // I need to Goto the Next record (HexxData.GotoNext;) // I need to Get the Record # (HexxData.RecNo;) // and test the Dbase.EOF (not HexxData.EOF) // and Append a Blank record (HexxData.AppendBlank;) // save an integer to a Field (HexxData.UpdFieldStr('this_game', inttostr(pattern.this_game)); ) // and Goto to the Record number (HexxData.GotoRecord(hexxdata_rec_no);) See examples of my code below Unit hexboard2.pas // declaring a Dbase file -- TXBase var HexxData, TraceFile: TXBase; procedure Thxboard.Open_db; begin if not fileExists('hex8.dbf') then CopyFile('blank.dbf', 'hex8.dbf', false); // how do I copy a blank.dfg file to hex8.bdf ??? HexxData := TXBase.create(nil); // I assume that this is how to create a replacement for a Dbase file HexxData.FileName := 'hex8.dbf'; HexxData.Active := true; HexxData.GotoBOF; // I need to Goto to the Bottom of File end; { Open_db } function Thxboard.pattern_is_db_current(pattern1: pattern_type): boolean; var str_x, str_o: array[1..8] of string; begin pattern_is_db_current := false; str(pattern1.x_piece[1], str_x[1]); // .. if (HexxData.GetFieldByName('x1_pos') = str_x[1]) and // I need to call a function GetFieldByName passing a string as the field name and comparing it with a character //.. (HexxData.GetFieldByName('x8_pos') = str_x[8]) then if (HexxData.GetFieldByName('o1_pos') = str_o[1]) and //.. (HexxData.GetFieldByName('o8_pos') = str_o[8]) then pattern_is_db_current := true; end; { pattern_is_db_current } {---------------------------------------------------------} procedure Thxboard.Find_pattern(var pattern1: pattern_type; var found: boolean); begin //,, HexxData.GotoNext; // I need to Goto the Next record end; { Find_pattern } {---------------------------------------------------------} procedure Thxboard.write_updated_pattern(var pattern1: pattern_type); var found: boolean; begin found := false; if pattern_is_db_current(pattern1) then { save pattern options to db } begin save_options(pattern1); hexxdata_rec_no := HexxData.RecNo; // I need to Get the Record # close_db; if trace_moves then //.. open_db; HexxData.GotoRecord(hexxdata_rec_no); // then I need to Goto to record # end else { save entire pattern to db }; begin while (not HexxData.EOF) and not found do // and test the Dbase.EOF (end of file) begin //.. end; if not found then begin { --- add a new record --- } HexxData.AppendBlank; // and Append a Blank record save_options(pattern1); HexxData.UpdFieldStr('this_game', inttostr(pattern.this_game)); // save an integer to a Field //.. hexxdata_rec_no := HexxData.RecNo; close_db; if trace_moves then //.. open_db; HexxData.GotoRecord(hexxdata_rec_no); // and Goto to the Record number end; // if found end; // else end; { write_updated_pattern } {---------------------------------------------------------} -- Proudly developing Quality Cross Platform Open Source Games Since 1970 with a Commodore PET 4016 with 16 KRAM http://pews-freeware-games.org (<--- brand new) -- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus