Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

csv - txt files

1 view
Skip to first unread message

Johan Kumps

unread,
Jun 5, 2000, 3:00:00 AM6/5/00
to
Hi all,

Can anyone tell me how I can access a csv (comma space delimited) file from
within Delphi 4.0 Client/server)

I want to be able to read and modify the data.

If it isen't possible to access this type of files, does anybody know a
conversion method to convert the csv to a file type that Delphi can access.

Thans in advance for your help,

Jason Wallace

unread,
Jun 5, 2000, 3:00:00 AM6/5/00
to
It's just a standard text file .... Open it like a text file, save it
like a text file, treat it like a text file ...

--


Jason Wallace
SL Software
Home: Dar...@SLSoftware.reno.nv.us
Work: Jason_...@Intuit.com


"Johan Kumps" <j.k...@planetinternet.be> wrote in message
news:8hh1b0$fid$1...@news.planetinternet.be...

David Gray

unread,
Jun 9, 2000, 3:00:00 AM6/9/00
to
A little known fact about the humble TTable - it can process CSV but the
operations are limited you can read the records sequentially. And you need to
setup what is called a schema file (.SCH extension but same name as the CSV
file. This facility has been available since Delphi 1. You can also export to a
CSV file.

Here is the Inprise/Borland documentation

Using ASCII Tables with Delphi
-------------------------------
Delphi supports using ASCII text files as tables, with limited
functionality. ASCII tables are intended for exporting
and importing data to and from other formats--in general, they are
not recommended for use as data sources for applications.

Each ASCII table requires a data file (generally with .TXT
extension) and a schema file (with the same base file name
and .SCH extension). The schema file contains information about
the structure of the table and the datatypes of its columns (fields).

ASCII tables are always opened for exclusive access. In other
words, no more than one application (session) can access an
ASCII table at one time. If you have opened an ASCII table at
design time, you must close it before running your application
that opens the table at run time.

Copying a table to ASCII format with Database Desktop or a TBatchmove
component will automatically create a schema file as well as the
ASCII data file. ASCII tables are always created with FIXED filetype.
When creating an ASCII table with Delphi (for example with BatchMove
or CreateTable methods), you must specify TableType as ttASCII. You
should not leave TableType as ttDefault.

ASCII tables do not support the following:
* Indexes (and therefore, any methods or functions that require an
index, such as GoToKey, SetRange, etc.)
* TQuery components (SQL)
* Deleting records
* Inserting records. Insert always appends the record to the end
of the table.
* Referential Integrity
* Blob datatypes
* DELIMITED tables do not allow modification (editing) of records

The Schema File
---------------
All information in the schema file is case-insensitive.
Here is a sample of what a schema file looks like:

[CUSTOMER] // File name with no extension.
FILETYPE = VARYING // Format: VARYING or FIXED
CHARSET = ascii // Language driver name.
DELIMITER = " // Delimiter for char fields.
SEPARATOR = , // Separator character
Field1 = Name,CHAR,12,0,0 // Field information
Field2 = Salary,FLOAT,8,2,12

The schema file has a format similar to Windows INI files.
The file begins with the name of the table in brackets.
The second line specifies the file format following the
keyword FILETYPE: FIXED or VARYING.
* In a FIXED format file, each field always takes up a fixed
number of characters in the file, and the data is padded with
blanks as needed.
* In a VARYING file, each field takes a variable number of characters,
each character field is enclosed by DELIMITER characters, and the
fields are separated by a SEPARATOR character. The DELIMITER and
SEPARATOR must be specified for a VARYING format file, but
not for a FIXED format file.

The CHARSET attribute specifies the name of the language
driver to use. This is the base file name of the .LD
file used for localization purposes.

The remaining lines specify the attributes of the table's
fields (columns). Each line must begin with "Fieldx = ",
where x is the field number (i.e. Field1, Field2, and so on).
Then comes a comma-delimited list specifying:
* Field name - Same restrictions as Paradox field names.
* Datatype - The field data type. See below.
* Number of characters or units. Must be <= 20 for numeric
data types. Total maximum number of characters for date/time
datatypes (including / and : separators).
* Number of digits after the decimal (FLOAT only).
* Offset - Number of characters from the beginning of the line
that the field begins. Used for FIXED format only.

The following data types are supported:
CHAR - Character
FLOAT - 64-bit floating point
NUMBER - 16-bit integer
BOOL - Boolean (T or F)
LONGINT - 32-bit long integer
DATE - Date field. Format specified by IDAPI.CFG
TIME - Time field. Format specified by IDAPI.CFG
TIMESTAMP - Date + Time field. Format specified by IDAPI.CFG

NOTE: You can specify Date and time formats in the BDE configuration
utility

Example 1 - VARYING format file
-------------------------------
CUSTOMER.SCH:

[CUSTOMER]
Filetype=VARYING
Delimiter="
Separator=,
CharSet=ascii
Field1=Customer No,Float,20,04,00
Field2=Name,Char,30,00,20
Field3=Phone,Char,15,00,145
Field4=First Contact,Date,11,00,160

CUSTOMER.TXT:

1221.0000,"Kauai Dive Shoppe","808-555-0269",04/03/1994
1231.0000,"Unisco","809-555-3915",02/28/1994
1351.0000,"Sight Diver","357-6-876708",04/12/1994
1354.0000,"Cayman Divers World Unlimited","809-555-8576",04/17/1994
1356.0000,"Tom Sawyer Diving Centre","809-555-7281",04/20/1994

Example 2 - FIXED format file
-----------------------------
CUSTOMER.SCH:

[CUSTOMER]
Filetype=Fixed
CharSet=ascii
Field1=Customer No,Float,20,04,00
Field2=Name,Char,30,00,20
Field3=Phone,Char,15,00,145
Field4=First Contact,Date,08,00,160

CUSTOMER.TXT:

1221.0000Kauai Dive Shoppe 808-555-0269 04/03/94
1231.0000Unisco 809-555-3915 02/28/94
1351.0000Sight Diver 357-6-876708 04/12/94
1354.0000Cayman Divers World Unlimited 809-555-8576 04/17/94
1356.0000Tom Sawyer Diving Centre 809-555-7281 04/20/94


Johan Kumps wrote:

> Hi all,
>
> Can anyone tell me how I can access a csv (comma space delimited) file from
> within Delphi 4.0 Client/server)
>
> I want to be able to read and modify the data.
>
> If it isen't possible to access this type of files, does anybody know a
> conversion method to convert the csv to a file type that Delphi can access.
>
> Thans in advance for your help,

--
Cut down on Junk EMAIL
Remove NOSPAM to reply

Wouter

unread,
Jun 12, 2000, 3:00:00 AM6/12/00
to
hi..
this is not awnsering your question but, before you run into someproblems
always write a record like this:
var t:textfile;
begin
assignfile(t,'c:\test.txt');
rewrite(t);
write(t,'"this is the record like"~"antoherfield"'+#10+#13);
DONT FORGET THE char 10!! :))

ltrz.


David Gray <gra...@NOSPAM.pcug.org.au> wrote in message
news:3940E4FF...@NOSPAM.pcug.org.au...

pgr...@dynasty.net

unread,
Jun 12, 2000, 3:00:00 AM6/12/00
to
"Wouter" <wout...@softhome.net> wrote:

|hi..
|this is not awnsering your question but, before you run into someproblems
|always write a record like this:
|var t:textfile;
|begin
|assignfile(t,'c:\test.txt');
|rewrite(t);
|write(t,'"this is the record like"~"antoherfield"'+#10+#13);
|DONT FORGET THE char 10!! :))

That should be #13#10

Phil


Wouter

unread,
Jun 13, 2000, 3:00:00 AM6/13/00
to
it should? ohh.. well this works fine tooooo
but i'll try it the other way around
<pgr...@dynasty.net> wrote in message
news:xJ715.42$uj3...@newsfeed.slurp.net...

> "Wouter" <wout...@softhome.net> wrote:
>
> |hi..
> |this is not awnsering your question but, before you run into someproblems
> |always write a record like this:
> |var t:textfile;
> |begin
> |assignfile(t,'c:\test.txt');
> |rewrite(t);
> |write(t,'"this is the record like"~"antoherfield"'+#10+#13);
> |DONT FORGET THE char 10!! :))
>
0 new messages