I need my pascal program to read and compare data from an external txt file lazarus / 16-Databases ---------------------------------------------------------------------- teochris · 2016-01-02 09:40 Hello, I have builded a pascal program and now I am facing the following difficulty. In my program I use variables like this fsarray: array[1..6] of integer; I have an external .txt file that is in the following format 1#31/12/1997#13#34#38#17#4#12 2#28/12/1997#20#23#30#19#41#8 3#24/12/1997#40#35#24#21#22#3 4#21/12/1997#15#3#38#32#19#20 5#17/12/1997#31#11#22#2#28#16 6#14/12/1997#32#6#19#30#27#4 7#10/12/1997#3#40#15#19#45#18 8#7/12/1997#7#14#31#44#18#14 9#3/12/1997#31#18#42#30#2#17 10#30/11/1997#5#37#42#11#6#7 11#26/11/1997#18#6#28#23#35#5 I need to do some comparisons and checks between my app and the external file, for example I want to check if fsarray: array[1] is equal to any of the values in the text file between the second and the third # Can this be done or do I have to create a database for such comparison (I have no idea of how I can create a database, what is the proper format for the database or even where to start from)? Can you please give me an example of your proposal? Any help would be appreciated! ---------------------------------------------------------------------- eny · 2016-01-02 09:56 This should be moved to the homework section. You can use a TStringList to read the file into memory. Then you can use for example ExtractWord(...) in the strutils unit to extract the values you need. ---------------------------------------------------------------------- balazsszekely · 2016-01-02 09:58 I think the most painless solution is to use TStringList, like this(just don't forget to add sysutils to the uses clauses): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  SL, SLExplode: TStringList;  I, J: Integer;begin  SL := TStringList.Create;  try    SL.LoadFromFile('text.txt');    SLExplode := TStringList.Create;    try      for I := 0 to SL.Count - 1 do      begin        Writeln('Line ' + IntToStr(I) + ':');        SLExplode.Clear;        SLExplode.Delimiter := '#';        SLExplode.DelimitedText :=  SL.Strings[I];        for J := 0 to SLExplode.Count - 1 do        begin          writeln('      Item ' + IntToStr(J) + '  =  ' + SLExplode[J]);          //do whatever you have to do with SLExplode[J]        end;      end;    finally      SLExplode.Free;    end;  finally    SL.Free;  end;  Readln;end. ---------------------------------------------------------------------- teochris · 2016-01-02 10:32 Quote from: GetMem on January 02, 2016, 10:58:20 amI think the most painless solution is to use TStringList, like this(just don't forget to add sysutils to the uses clauses): Excellent and very helpful advise and example Can I also read the .txt file from internet instead of the local disk? ---------------------------------------------------------------------- Jurassic Pork · 2016-01-02 10:37 hello, you can also load your datas in a stringgrid : example : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var myGrid : Tstringgrid;beginmyGrid := TStringGrid.Create(nil);with mygrid dobeginLoadFromCSVFile('myTextFile.txt','#',false);Memo1.Append('Cols : ' + inttoStr(ColCount) + ' - ' +             'Rows : ' + inttoStr(RowCount));Memo1.Append('First Data Line : ' +              Cells[2,1] + ' - ' +  Cells[3,1] + ' - ' + Cells[4,1] + ' - ' +            Cells[5,1] + ' - ' +  Cells[6,1] + ' - ' + Cells[7,1]);end;// to be defined  and maybe use a stream ( ex LoadFromCsvStream) to load from internet. ---------------------------------------------------------------------- balazsszekely · 2016-01-02 10:42 Quote@teochris Can I also read the .txt file from internet instead of the local disk?Yes, you can download the file with synapse, indy, etc..Please search the forum, you will find a lot of examples. ---------------------------------------------------------------------- teochris · 2016-01-02 10:49 Quote from: GetMem on January 02, 2016, 11:42:10 amQuote@teochris Can I also read the .txt file from internet instead of the local disk?Yes, you can download the file with synapse, indy, etc..Please search the forum, you will find a lot of examples. You were really helpful - THANKS