?
Solved

How do you write a text file from a "type record" ?

Posted on 2000-02-08
7
Medium Priority
?
155 Views
Last Modified: 2012-05-04
type
   ExtStruc = record
     ExtName : String [30];
     ExtComment1 : String [60];
     ExtComment2 : String [60];
   end;
var
   ExtFile : Textfile;
   ExtRec  : ExtStruc;
begin
  AssignFile(ExtFile, 'd:\test\tst.txt');
  Rewrite(ExtFile);
 ExtRec.ExtName :=  'john doe';
  ExtRec.ExtComment1 := 'comment line 1 test';
  ExtRec.ExtComment2 := 'comment line 2 test';

{  the following writeln statement works, but is there
  a way to use the RECORD ExtRec instead? I get an error. :(}

 { WriteLn(ExtFile, ExtRec.ExtName, ExtRec.ExtComment1,                ExtRec.ExtComment2);}


  I tried the following line and i get an error.  I dont want to specify
  all the different fields like the above writeln statement, that would
  be terrible when you have a big record layout.

      WriteLn(ExtFile, ExtRec);  <---- i get an error


   CloseFile(ExtFile);
0
Comment
Question by:waipahu
7 Comments
 
LVL 1

Expert Comment

by:XAN
ID: 2501530
you can use any common delimeters like TAB #09 to get one string from one record. why not? :)
0
 

Accepted Solution

by:
abrooks earned 150 total points
ID: 2501593
To perform the type of IO you want do not use the text file IO routine.  Instead use the BlockRead and BlockWrite routines.  Pay particular attention to Reset and ReWrite Statements along with the Block Read and Write statements.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2501597
The trick is to change these definitions:

var
   ExtFile : Textfile;
   ExtRec  : ExtStruc;

to

var
  ExtRec  : ExtStruc;
  ExtFile : File of ExtStruc;

And then do this:

 Write(ExtFile, ExtRec);

The difference here is that the file created will be a binary one, rather than a text one...

Cheers,

Raymond.
 
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 

Expert Comment

by:abrooks
ID: 2501649
Randy! Randy! Randy! Get Down!
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2501694
Hmm...
0
 

Author Comment

by:waipahu
ID: 2501817
Thanks, is there anyway I could get it in
ascii? This file will be ftp to an HP unix machine
which will then be loaded unto a database.
I can't use binary. :(
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2501840
No, you will need to write out the fields of the records individually.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question