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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.DB to .TXT

Status
Not open for further replies.

RobPouwelse

Technical User
Nov 19, 2001
77
NL
I need to convert a .db file (Paradox 7) to a text file.
I know the architecture of the text file must be

cell[tab]cell[tab]cell[tab]cell (eol)
cell[tab]cell[tab]cell[tab]cell (eol)

until i get to (eof)..

the problem i have is: How can i get that cell information?
the only function i found that would (probably) solve my problem is "TCustomDBGrid.GetFieldValue".. But when i try to implement it into my program it gives an "undeclared identifier GetFieldValue".. I did include the right unit so that couldn't be it..

tnx in advance,
 
Can you not just set up a TTable component pointing to the .Db file, open it, go to the first record, cycle through the fields outputting the field values (or field names for headers) to a text file, then perform a 'while NOT EOF' on the table.
Hope this helps.
Steve
 
the problem is : how do i go to records (cycle through them).. and how can i get the fieldvalues? i tried the above method "TCustomDBGrid.GetFieldValue" but that doesn't work ..
 
I can't see the need for the DBGrid usage. Point the TTable to the file (i.e. Customer.db) and set Active to True. Then run through the Fields using :
for i := 0 to (Table1.FieldCount - 1) do
begin
// To get the field name
tpFieldName := Table1.Fields.Name;
// To read the entry as a string
tpString := Table1.Fields.AsString;
end;

Hope that this gets you started. The code is off the top of my head so is not 100% guaranteed. You should be able to run similar code making use of the DBGrid if you really need to.
Steve
 
You did that out of you're head??... omg, i need a book to even write a function :)

if i'm correct tpFieldName and tpString are both variables i have to declare?? if so, I know tpString is a String (doh!:)).. tpFieldName is a String also??

btw: am i correct if tp means template??
 
The 'tp' prefix is just a convention we've adopted.
Having spent a little time I've come up with the following code :
(The example uses a TTable component, pointing to the DBDemos Alias and the CUSTOMER.DB table, a button used to call the following procedure and a TRichEdit component just to prove the point to myself).

procedure ......;
var
tpI : Integer;
begin
RichEdit1.Lines.Clear;
Table1.Active := True;
for tpI := 0 to (Table1.FieldCount - 1) do
begin
// Output the Field Name
RichEdit1.Lines.Add(Table1.Fields[tpI].FieldName);
end;
RichEdit1.Lines.Add('');
// Now cycle through the table.
Table1.First;
while not Table1.EOF do
begin
// Output entries in first two fields
RichEdit1.Lines.Add(Table1.Fields[0].AsString + Table1.Fields[1].AsString);
Table1.Next;
end;
end;

The example first outputs a list of the field names, then outputs the first two field values for each record. It's not exactly what you initially asked for but its a step in the right direction and the theory can be used to achieve your aim (I hope)
Hope that this helps.
Steve
 
Tnx a lot!, the command Table1.First; was really usefull cause then it always starts at the beginnen.
then the Table1.Next; .. man, it sounds so logical. (well, it is) :)

I didn't use the FieldsName because i only needed to have the value (otherwise the architecture of the text wouldn't be right).. But what i don't know is the difference between RichText and a Memo.. and does it make a difference that i used the Memo instead??

Well, i still got a problem... here my procedure.
=======================================================
Code:
procedure TForm1.SaveasText1Click(Sender: TObject);
var i : integer;
    tpString : string;

begin
  Memo1.Visible := True;
  Memo1.Clear;
  Table1.Active := True;
  Table1.First;
  while not Table1.Eof do
  begin
    for i := 0 to (Table1.FieldCount - 1) do
      begin
        tpString := Table1.Fields[i].AsString; //for some reason i don't get a value}
        if i > 0 then tpString := tpString + '[tab]' + tpString; // i do however get the "[tab]"'s}
      end;
    Memo1.Lines.Append(tpString);
    Table1.Next ;
  end;
end;
=======================================================

do you know why i don't get any value's??
 
ignore my last post... i posted before i thought (again!:))

i solved the problem..


for i := 0 to (Table1.FieldCount - 1) do
begin
tpString := Table1.Fields.AsString;
if i > 0 then tpString := tpString + '[tab]' + tpString;
end;

i would constantly overwrite my values... stupid me..
now it's this :

for i := 0 to (Table1.FieldCount - 1) do
begin
NewString := Table1.Fields.AsString;
if i > 0 then OldString := OldString + '[tab]' + NewString
else OldString := NewString; //otherwise i would get a tab first.. and i don't want that :)}
end;

anyway, Tnx! for your help.. it's greatly appreciated (if i speled it right :D)
 
ignore my last post... i posted before i thought (again!:))

i solved the problem..


for i := 0 to (Table1.FieldCount - 1) do
begin
tpString := Table1.Fields.AsString;
if i > 0 then tpString := tpString + '[tab]' + tpString;
end;

i would constantly overwrite my values... stupid me..
now it's this :

for i := 0 to (Table1.FieldCount - 1) do
begin
NewString := Table1.Fields.AsString;
if i > 0 then OldString := OldString + '[tab]' + NewString
else OldString := NewString; //otherwise i would get a tab first.. and i don't want that :)}
end;

anyway, Tnx! for your help.. it's greatly appreciated (if i spelled it right :D)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top