Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-09

TDBF File is NOT created!!! FieldDefs.add( field, param, param ) does NOT create fields.

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter E Williams

Hi all,

This one is really puzzling. I thought that I was doing everything okay to generate a new TDBF file... but I cannot create the file. The following is tracetestUnit1.pas which is a test unit to create a dBase format TDbf database file.

Output to memo1 follows:

FilePath
= /home/pewink/Public/My_code/Lazarus_source/pewink/Hexxpawn/lazarus/0.5.alpha/ TableName = hex8_log.dbf
Trace File does not exist.
closing Trace file.
Starting to add fields with .FieldDefs
finished adding fields.
closing trace file.
Opening Trace File.
Exception opening trace file.
-----
Note : the FilePath is confirmed to exist.

As you can see, I add the fields with the .FieldDefs field. I then close the file and the TDbf file is NOT created. What am I doing wrong???

unit tracetestUnit1;
{$mode objfpc}{$H+}
interface

uses
Classes, SysUtils, dbf, FileUtil, LResources, Forms, Controls, Graphics,

  Dialogs, StdCtrls, DB, dbf_common;
const
  filename_Trace_File_DBF = 'hex8_log.dbf';
  TXBaseConst = xBaseVII;
type
  { TForm1 }
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Trace_File_DBF: TDbf;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    procedure open_trace_file;
  end;
var
  Form1: TForm1;
  Trace_File_DBF_open : boolean;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
  open_trace_file;
end;
procedure TForm1.open_trace_file;
var
  S : String;
  I : integer;
begin
  S := Application.ExeName;
  // hack for Mac
  I := Pos('.app/Contents/MacOS/', S);
  if (I > 0) then
    S := Copy(S,1, I+3);
  try
    begin
      Trace_File_DBF.TableLevel := Longint(TXBaseConst);
      Trace_File_DBF.FilePath := ExtractFilePath(S);
      Trace_File_DBF.TableName := filename_Trace_File_DBF;
      memo1.lines.add( 'FilePath = ' + Trace_File_DBF.FilePath );
      memo1.lines.add( 'TableName = ' + Trace_File_DBF.TableName );
      Trace_File_DBF.TableLevel := Longint(TXBaseConst);
      if not FileExists( filename_Trace_File_DBF ) then
      begin
           memo1.lines.add( 'Trace File does not exist.' );
           Trace_File_DBF.TableLevel := Longint(xBaseVII);
           memo1.lines.add( 'closing Trace file.' );
           Trace_File_DBF.Close;
           with Trace_File_DBF.FieldDefs do
                begin
                     memo1.lines.add( 'Starting to add fields
with .FieldDefs' );
                     // Trace_File_DBF.FilePathFull := ????????
                     with Trace_File_DBF.FieldDefs do
                          begin
                               //Clear;
                               Add( 'game_counter', ftinteger, 0,
True );
                               Add( 'turn_counter', ftInteger, 0,
True  );
                               Add( 'player_o_move_from_row', ftInteger,
0, True  );
                               Add( 'player_o_move_from_col', ftInteger,
0, True  );
                               Add( 'player_o_move_to_row', ftInteger,
0, True  );
                               Add( 'player_o_move_to_col', ftInteger,
0, True  );
                               Add( 'player_x_move_from_row', ftInteger,
0, True  );
                               Add( 'player_x_move_from_col', ftInteger,
0, True  );
                               Add( 'player_x_move_to_row', ftInteger,
0, True  );
                               Add( 'player_x_move_to_col', ftInteger,
0, True  );
                               Add( 'record_no', ftInteger, 0, True  );
                               Add( 'winner', ftString, 12, True  );
                               Add( 'move_options', ftString, 25,
True  );
                               Add( 'pawn_move_rating', ftString, 25,
True  );
                               Add( 'successful_move', ftBoolean, 0,
True  );
                               Add( 'pawn_no', ftInteger, 0, True  );
                               Add( 'direction', ftInteger, 0, True  );
                               Add( 'option_was', ftString, 25, True  );
                          end; // with
                     memo1.lines.add( 'finished adding fields.' );
                end; // with
           memo1.lines.add( 'closing trace file.' );
           Trace_File_DBF.Close;
      end; // then
      memo1.lines.add( 'Opening Trace File.' );
      Trace_File_DBF.Open;
      Trace_File_DBF_open := true;
      memo1.lines.add( 'FindLast record.' );
      Trace_File_DBF.FindLast;
    end; // try
  except
    //showmessage( 'Exception opening trace file.' );
    memo1.lines.add( 'Exception opening trace file.' );
  end;
end; { open_trace_file }
{---------------------------------------------------------}
initialization
  {$I tracetestunit1.lrs}
end.
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)

Reply by email

waldo kitty
to Peter E Williams: This one is really puzzling. I thought that I was doing everything okay to generate a new…
Peter E Williams wrote 14 lines
Hi all, This one is really puzzling. I thought that I was doing everything okay to generate a new TDBF file... but I cannot create the file. The following is tracetestUnit1.pas which is a test unit to create a dBase format TDbf database file. Output to memo1 follows: FilePath = /home/pewink/Public/My_code/Lazarus_source/pewink/Hexxpawn/lazarus/0.5.alpha/ TableName = hex8_log.dbf Trace File does not exist. closing Trace file.

ummm.... the file doesn't exist yet you close it anyway without it having been opened?

Show quoted text 5 lines
Starting to add fields with .FieldDefs finished adding fields. closing trace file. Opening Trace File. Exception opening trace file.

Reply by email