Solved

how can i change a txt file to date base file?

Posted on 1998-02-10
15
162 Views
Last Modified: 2010-04-04
how can i take an infomation from txt file
and add it to the DB information?
please give me an example and
source.
0
Comment
Question by:tomerlei
  • 7
  • 4
  • 2
  • +2
15 Comments
 
LVL 2

Expert Comment

by:mvz121697
ID: 1358856
This example reads in the file c:\test.txt in a table
(Before use, drop a table (Table1) on your form, and connect it to the database/tabel)


Var F:TextFIle;
   cFile,cLine,cField1,cField2:string;

cFile:='c:\test.txt';
Assign(F,cFIle);
try
 reset(F);
 while not eof(F) do begin
   Readln(F,cLine);
   cField1:=Copy(cLine,1,10);
   cField2:=Copy(cLine,11,10);
   cField3:=Copy(cLine,21,10);
   Table1.Append;
   Table1.FieldByName('Field1').asstring:=cField1;
   Table1.FieldByName('Field2').asstring:=cField2;
   Table1.FieldByName('Field3').asinteger:=StrToInt(cField3);
   Table1.Post;
 end;  
Finally
  CloseFile(f)
end;


Greetings
MvZ
0
 
LVL 4

Author Comment

by:tomerlei
ID: 1358857
but it says:
incompaible types 'TPersistent' and 'text'
and he take the curser to the assign command.
What need i do
0
 
LVL 4

Author Comment

by:tomerlei
ID: 1358858
<h1>answer me please</h1>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:itamar
ID: 1358859
Hi tomerlei,

there is another approach to this question. With BDE you can map a text file and treat it almost exactly as a local table. Associating with all controls that deals with a "real" data table. If your interested I can give you more details.

Bye,
Itamar
0
 
LVL 5

Expert Comment

by:inter
ID: 1358860
In mvz's answer use AssignFile not Assign (which is a method for opening files before delphi-BP7.0- etc.) And add the following for trimming extra spaces. This example assumes that you have three fields in text file in three columns. Field one is first 10 chars, fields to is chars between 10 and 21, etc...

...
cField1:=Trim(Copy(cLine,1,10));
cField2:=Trim(Copy(cLine,11,10));
cField3:=Trim(Copy(cLine,21,10));
...

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358861
Why don't you just store the contents of that txt file in a Memo field of tTable?
0
 
LVL 2

Expert Comment

by:mvz121697
ID: 1358862
Sorry, for the delay, but like 'Inter' said,
i made a mistake in with assign (should be assginFile)
(I typed it out-of-the head).

Greetings,
MvZ
0
 
LVL 4

Author Comment

by:tomerlei
ID: 1358863
and how the text file should  to be.
my fields is:
Company
First name
Last name
City
Street
Street num
Zip/postal code
0
 
LVL 4

Author Comment

by:tomerlei
ID: 1358864
and how the text file should  to be.
my fields is:
Company
First name
Last name
City
Street
Street num
Zip/postal code
0
 
LVL 2

Expert Comment

by:mvz121697
ID: 1358865
In my previous example i was referring tto a textfile where
all the fields of a record where on 1 line, with fixed
field-length's
If the fieldss are on seperate lines in you're text file then
use something like this:

while not eof(F) do begin
  Table1.Append;
  Readln(F,cLine);
  Table1.FieldByName('Company').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Firstname').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Lasyname').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('City').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Street').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Street num').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Zip').asstring:=cLine;
  Table1.Post;
end;

Greetings,
MvZ

0
 
LVL 4

Author Comment

by:tomerlei
ID: 1358866
thank you mvz!!!
but answer me this i want to give you the points!!!

0
 
LVL 4

Author Comment

by:tomerlei
ID: 1358867
mvz
Do you remember that i asked you how can i search a word
on a DBgrid?
it's locate me on one word.
i need
that when i click the button agian
it's find me the next word.  
0
 
LVL 4

Author Comment

by:tomerlei
ID: 1358868
how can i do that?






























































0
 
LVL 4

Expert Comment

by:itamar
ID: 1358869
Hi tomerlei,

there is another approach to this question. With BDE you can map a text file and treat it almost exactly as a local table. Associating with all controls that deals with a "real" data table. If your interested I can give you more details.

Bye,
Itamar
0
 
LVL 2

Accepted Solution

by:
mvz121697 earned 50 total points
ID: 1358870
> Thank you mvz!!!
but answer me this i want to give you the points!!! <

Ok.
For the Locate / Findnext question,
maybe you can use the Table's - filter property to show only the
lines which have the words. Then you can simple do a
Table.next

Greetings,
MvZ
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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