Reading Text from File

ReaperUser101 0 Tallied Votes 203 Views Share

Hi guys

The just of what i whant to do is read lines of text from a file until it reaches
a delimiter and then execute that text in a query and repeat the process till
there is no more text. I am using Delphi 6(don't have a choice) and the text is SQL in a .txt file

The code I provided does not work because it doesn't use the delimiter(defaults to whitespace)
and a stringlist is not compatable.

If anyone has any advice let me know
Great thanks in advance

sqlRead := TStringList.Create;
  sqlRead.Delimiter := '|';

  for i := 0 to sqlRead.Count-1 do
  CDSADOQuery1.SQL.Text := sqlRead;
  CDSADOQuery1.Active := True;
pritaeas 2,130 ¯\_(ツ)_/¯ Moderator Featured Poster

Set StrictDelimiter to True to disable the space delimiter.

ReaperUser101 0 Newbie Poster

I don't think I have that setting, I'm using delphi 6 and read in another source that it doesn't exist yet in Delphi 6.

pritaeas 2,130 ¯\_(ツ)_/¯ Moderator Featured Poster

Found a comment that in older versions the space is always used as delimiter, so perhaps this is the case here. You may have to parse the file yourself, to get it right. If you are sure that the pipe character is not used in your data, you can use Pos(), Copy() and Delete() to get your queries.

ReaperUser101 0 Newbie Poster

Thanks for the replies but managed it with the next code although it is faulty due toe the fact that if the one table exists it doesn't create the next one but works at least.

ReaperUser101 0 Newbie Poster

lsLocation is a string that gets the current directory (The location of the .exe file) where the text file is

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.