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

export an ascii delimited file to paradox table

Status
Not open for further replies.

zlaja

Programmer
Oct 1, 2001
14
CA
I would like export my ascii delimited file (delimiter is space) to paradox (or dBase table). Can someone helps me?
 
The best way of doing this would be to open the text file into a stringlist.

MyStringList.Lines.LoadFromFile('C:\MyFileName.txt');

After doing this, in a repeat loop similar to the one show, read each line of text and search for the spaces one at a time. You know which column corresponds to which field in your table so it should be easy to save in this manner.

var
X, Y : Integer;
S : String
begin
X := 0
repeat
S := MyStringList.Lines[X];
Y := Pos(' ',S);

{Locate the spaces as many times as you require using the pos function, not forgetting to delete upto the located space each time otherwise you will locate the same space each time}


Table1.Last;
Table1.Append;
Table1.FieldByName('MyField').AsString := TempString;
" "
" "
Table1.Post;
X := X + 1;
until X = MyStringList.Lines.Count;
end;

If your still stuck, check the helpfile on how to use strings and stringlists. Arte Et Labore
 
Here's another example:
Code:
var
  TempStringList : TStringList;
  ALineStrList   : TStringList;
  ANewTable      : TTable;
  i, j           : Integer;
begin
  if OpenDialog.Execute then
  begin
    TempStringList := TStringList.Create;
    ALineStrList   := TStringList.Create;
    ANewTable      := TTable.Create(Self);
    try
      TempStringList.LoadFromFile(OpenDialog.FileName);
      if (TempStringList.Count = 0)then
       Exit;
      ALineStrList.Text := StringReplaceTempStringList.Strings[0], ' ', #10, [rfReplaceAll]);
      // Creating fields
      with ANewTable do
      begin
        StoreDefs := False;
        TableType := ttParadox;
        TableName := 'C:\MyNewTable.db';
        with FieldDefs do
        begin
          for i := 0 to ALineStrList.Count - 1 do
          begin
            with AddFieldDef do
            begin
              Name     := Format('Field_%d', [i + 1]);
              DataType := ftString;
              Size     := 50;
            end;
          end;
        end;
        CreateTable();
        // Filling table with data.
        Active := True;
        for i := 0 to TempStringList.Count - 1 do
        begin
          ALineStrList.Text := StringReplaceTempStringList.Strings[0], ' ', #10, [rfReplaceAll]);
          Insert;
          for j := 0 to Fields.Count - 1 do
          begin
            FieldByName(Format('Field_%d', [j + ])).asString := ALineStrList.Strings[i];
          end;
          Post;
        end;
        Active := False;
      end;
    finally
      ANewTable.Free;
      ALineStrList.Free;
      TempStringList.Free;
    end;
  end;
end;
[\code]
  But here made a lot of assumptions like i assume that you need to store data as string only, and that every row contains all fields' values. If i had more time i would add code for determening maximal length of a value e.t.c. But this Eric's example and this can be something you may start with.
   Hope that helps.

--- markus
 
Thank you EricDraven and McMerfy. It works well but for small files. My text files are about 7-8 Mb, and I can have until 30..35 files ( I export each text file to paradox table end after that with SQL statment I put all data in simple table for make the reports). I tried export that using schema files and batch move but it doesn't work well. In both cases it's slow.

Thanks anyway!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top