Solved

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

Posted on 1998-02-10
15
161 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
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from 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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now