Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing a Text File App

Status
Not open for further replies.

minckle

Programmer
Mar 17, 2004
142
GB
Delphi 5 -
Im trying to create a small app to import a text file into a database. i.e. I've got tick boxes for 'Does file include Column Headings?' and 'Type of Text File' 'Comma Seperated' / 'Tab Seperated'

My problems arrives when am trying to map the fields

Basically, depending on what the User selects 'Tab' or 'Comma', I want to display the first line in the text file, down 1 column in a StringGrid.

therefore if they pick 'Tab' it does the following -

Text File:
Forename Surname Mob Number

StringGrid:
Forename
Surname
MobNumber

Orif they pick 'Comma' it does the following -

Text File:
Forename,Surname,Mob Number

StringGrid:
Forename
Surname
MobNumber

My current code users 'CommaText' and therefore shows the StringGrid as
Forename
Surname
Mob
Number

Hope this is easy to understand - Any help or tips are welcome

Thanks

below is my current code:

oFileStrings := TStringList.Create;
oRowStrings := TStringList.Create;
oFileStrings.LoadFromFile(GetFileName);
for i := 0 to 0 do
begin
oRowStrings.Clear;
if GetColumnHeadings = False then
oRowStrings.CommaText := oFileStrings[0]
else
oRowStrings.CommaText := oFileStrings[1];
StringGrid1.cols.Assign(oRowStrings);
end;
oFileStrings.Free;
oRowStrings.Free;
 
That's the behavior of the CommaText property of TStrings. (Look it up in help.) Either eliminate the spaces in your input string or enclose the names in quotes.
 
its not that easy thou is it.

this is an text file import routine im trying to create, where the customer can import a text file into a db. its not a very good thing to say 2 a customer to go through a text file and ask them to put quotes in there files.

is there any other ways of doing it
 
Not with the CommaText property of TStrings. Process the text yourself.

Why insist on barking up the wrong tree?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top