chinesenax.blogg.se

Delphi read csv file
Delphi read csv file







Otherwise the GetValue function is a safe wrapper to access the contents of the array.When reading comma separated files with TStringList.CommaText, there is a problem, if the value between commas contains a space it is broken up to two separate values. If you are 100% sure that you don't exceed the boundaries of the array you can access it directly. ParseFile parses the file and returns it in a two-dimensional dynamic array. IF Paragraph>=LENGTH(ARR) THEN SetLength(ARR,SUCC(Paragraph)) įUNCTION GetValue(CONST ARR : TTwoDimIntArr Chapter,Paragraph : Cardinal) : Cardinal ĮLSE IF Paragraph>=LENGTH(ARR) THENįUNCTION ParseFile(CONST FileName : STRING) : TTwoDimIntArr IF Chapter>=LENGTH(ARR) THEN SetLength(ARR,SUCC(Chapter)) PROCEDURE SetValue(VAR ARR : TTwoDimIntArr Chapter,Paragraph,Value : Cardinal)

delphi read csv file

TTwoDimIntArr = ARRAY OF ARRAY OF Cardinal I'd like to avoid using a database table because: 1) the amount of data isn't that large (1500 lines in the CSV file, i.e., 1500 paragraphs), 2) the extra overhead of a database engine (I only need to read data, not write data), 3) the frequency that this function will be called from within the program.

delphi read csv file delphi read csv file

So in the example above, I'd like to pass 2,2 to a function and have it return "51" (integer) The CSV file is sorted numerically, that is: 1,1,30 // first paragraph of first chapter (line # 1)ġ,2,56 // second paragraph of first chapter (line # 2)ġ00,23,78 // last paragraph of last chapter (line # 1500)

delphi read csv file

I want to be able to retrieve this last value, i.e., the number of words, by providing a function the first two values (i.e., the chapter and paragraph number). The CSV file exists in format of:Ĭhapter number, Paragraph number, Total number of words in the paragraph I have the need to be able to quickly identify a value from a CSV file (less than 15kb in size). I am looking for advice on how to best handle a programming task using Delphi 7.









Delphi read csv file