Solved

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

Posted on 1998-02-10
15
159 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

15 Experts available now in Live!

Get 1:1 Help Now