Solved

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

Posted on 1998-02-10
15
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

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!

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 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