ICsv interface

ICsv interface is used to work with csv files.

 

Added in QM 2.3.0.

 

Use function CreateCsv to create a csv object. To work with it, use ICsv interface. Example:

 

str s ss
ICsv v=CreateCsv
v.FromFile("$my qm$\test.csv")

int nr=v.RowCount
int nc=v.ColumnCount
int r c
for r 0 nr
	out "--- row %i ---" r
	for c 0 nc
		s=v.Cell(r c)
		out s
		s.trim
		v.Cell(r c)=s

v.ToString(ss)
out ss

 

Functions

 

interface# ICsv :IUnknown
	[p]Separator($sep)
	FromString($s)
	ToString(str*so)
	FromFile($file)
	ToFile($file [append])
	FromQmGrid(hwnd [flags])
	ToQmGrid(hwnd [flags])
	Clear()
	[g]#ColumnCount()
	[g]#RowCount()
	[g]$Cell(row col)
	[p]Cell(row col $value)
	RemoveRow(row)
	#AddRowMS(row ncells $cells)
	#AddRowLA(row ncells lpstr*cells)
	#AddRowSA(row ncells str*cells)
	{3426CF3C-F7C1-4322-A292-463DB8729B54}
dll "qm.exe" ICsv'CreateCsv

 

 


 

CreateCsv - creates a csv object and returns ICsv interface pointer. Since it is a COM object, it is destroyed automatically when goes out of scope.

 


 

Separator - changes default separator that is used when parsing and composing csv. Example: v.Separator=";". Default separator on most computers is comma, but somewhere it is semicolon. It can be changed in Control Panel -> Regional and Language Options -> Customize... -> List Separator.

 


 

FromString - parses a csv string and creates table in memory. The table is managed by the csv object.

 

Error if the csv string contains errors or uses different separator.

 


 

ToString - composes a csv string from the table.

 


 

FromFile - parses a csv file and creates table in memory.

 

Error if the csv file contains errors or uses different separator.

 

QM 2.3.0. Can use syntax ":resourceid filepath" to add the file to exe resources.

 


 

ToFile - saves the table to a csv file. flags: 1 - append.

 


 

FromQmGrid - creates table from a QM_Grid control. flags: 1 - except first column; 2 - trim spaces.

 


 

ToQmGrid - populates a QM_Grid control. flags: 1 - only first column; 2 - except first column.

 


 

Clear - deletes all rows.

 


 

ColumnCount, RowCount - gets the number of columns and rows in the table.

 


 

Cell - gets or sets cell value. See the above example. Note that the returned value becomes invalid after calling a function that modifies the table, and therefore you should assign it to a str variable, like in the example.

 


 

RemoveRow - removes a row.

 


 

AddRowMS, AddRowLA, AddRowSA - add a row.

 

row - 0-based row index where the new row must be inserted. Use an invalid index (e.g. -1) to add to the end.

ncells - number of cells to add. If the table is empty, it sets the number of columns. Else it must not be more than the number of columns.

cells - cell values.

 

Each of these functions differs only by the format of values (cells). With MS, cells must be a multistring, ie single buffer containing multiple string separated by null character. With LA, cells must be address of first variable in an array of lpstr variables. With SA - str variables. If cells is omitted or 0, adds an empty row. You can use Cell to set cell values.

 


 

Notes

ICsv functions are not thread-safe. Don't use a single variable in multiple threads simultaneously. It can damage data. If needed to use in multiple threads, use lock.