Board index » delphi » Reading Text file to Write to a Dbase file

Reading Text file to Write to a Dbase file

Help

I would like to know how I can open a text file with fixed length records,
read the fields and then write the data read into a Dbase file. I currently
have the code written to sequentially process the text file but I am at a
loss as to how to open the dbase file, write to the required fields and then
return to the text file to process the next record (in other words how to
switch between the two files).  Any help on this would
be greatly appreciated.

Alan Bell (belalan @cam.org)

 

Re:Reading Text file to Write to a Dbase file


On Mon, 29 Nov 1999 07:55:40 -0500 Alan Bell wrote:

Quote
> Help

> I would like to know how I can open a text file with fixed length records,
> read the fields and then write the data read into a Dbase file. I currently
> have the code written to sequentially process the text file but I am at a
> loss as to how to open the dbase file, write to the required fields and then
> return to the text file to process the next record (in other words how to
> switch between the two files).  Any help on this would
> be greatly appreciated.

Maybe sth. like that could give you a hint:
type
  tr = {packed} record //uncomment packed if necessary
    {insert the file's structure here}
    { sth. like
    i: integer;
    c: char; }
  end;
var
  f: file of tr;
  r: tr;
...
  AssignFile(f, 'filename');
  Reset(f);
  repeat
    readln(f, r);
    {assign db-values here
     sth. like
     db_int := r.i;}
    {post to db}
  until Eof(f);
  CloseFile(f);

Bye, Udo

Re:Reading Text file to Write to a Dbase file


Quote
Alan Bell wrote in message <81tt4n$...@tandem.CAM.ORG>...
>... I currently
>have the code written to sequentially process the text file but I am at a
>loss as to how to open the dbase file, write to the required fields and
then
>return to the text file to process the next record (in other words how to
>switch between the two files). ...

1. Drop a Table onto your form from the 'DataAccess' tab. Set the directory
name for the Table in the Object Inspector, and then set the Tablename
property. You might need to set Tabletype too--I forget.

2. Let's assume two fields from your text file, in string variables F1 and
F2, and that fields with these names exist in your dBase table.

--open text file called, say, myText
with Table1 do begin
  Open;
  while not eof(myText) do begin
    --readln of myText and store field values in F1 and F2
    Insert;
    FieldByName('F1').AsString:=F1;
    FieldByName('F2).AsString:=F2;
    Post
    end;
  Close
  end

We Bells must stick together!

Regards,

Bill Bell

Other Threads