STRINGS(1,2,3,4,5)
PURPOSE
This function will manipulate a TStrings or TStringList property in a form object.
PARTS
1 f/c/e | Required - The object name on the current form. |
2 f/c/e | Required - The property name, generally 'Lines' or 'Items'. |
3 sac | Required - What to do: |
stCount - Return the number of lines in the list.
stGetLine - Get a specific line in the list.
stGetText - Get all the lines in the list and return as a single string. |
stSetLine - Replace a current line in the list. |
stSetText - Replace all the lines in the list using a single string. The lines should be divided by cr/lf pairs at the end of each line. |
stClear - Remove all the lines from the list. The count will be reset to 0. |
stAddLine - Add a new line to the end of the list. |
stDelLine - Delete a specific line from the list. |
stInsLine - Insert a new line into a specific location. |
stLoad - Load a set of lines from a file on the disk. |
stSave - Save a set of lines to a file on the disk. |
stSort - Sort the lines into ascending order. NOTE: This works only for TStringList properties. |
stFind - Find a line based on the line's value. NOTE: This works only for TStringList properties. Also the list must be sorted (see stSort above) or you will not find the correct line. |
StLocate - Finds a line based on the line's value without being sorted.
4 f/c/e | This part depends on the option specified in part 3. |
stSetLine - Required - This is the string you want to use to replace a current line.
stSetText - Required - This is the string you want to use to replace all the lines.
stAddLine - Required - This is the string you want to add at the end of the list.
stInsLine - Required - This is the string you want to insert into the list.
stLoad or stSave - Required - This is the name of the file you want to use, must include complete path.
stFind - Required - This is the value you want to search for.
NOTE: In options stGetLine and stDelLine you must put a place keeping comma since part 5 is required for those but part 4 is not.
5 f/c/e | This part depends on the option specified in part 3. |
stGetLine - Required - The line number you want to retrieve.
stSetLine - Required - The line number you want to replace.
stDelLine - Required - The line number you want to delete.
stInsLine - Required - The line number you want to insert at. This means that this line and all others after this line will be moved down one and the value in part 4 will be inserted into this position.
RETURN TYPE - Varies
The return value depends on the option set in part 3.
stCount - I - Returns the number of lines in the list.
stGetLine - A - Returns the line value.
stGetText - A - Returns the string with all the lines.
stSetLine - I - Returns the number of lines in the list.
stSetText - I - Returns the new number of lines in the list.
stClear - I - Returns the new number of lines in the list. Should be 0.
stAddLine - I - Returns the new number of lines in the list.
stDelLine - I - Returns the new number of lines in the list.
stLoad - I - Returns the new number of lines in the list.
stSave - L - Returns .T. if the file was saved, .F. if not.
stSort - L - Returns .T. if the list was sorted, .F. if not.
stFind - I - Returns the line number of the string if found. If it isn't the function will return 0.
COMMENTS
Several objects have either TStrings or TStringList as properties. These include TTASComboBox, TMemo and the non-visual object TTASStrList. The only way to manipulate those properties is through this function.
See Also GFLD(1,2,3,4)
NOTE: The special alpha constants above (stCount through stFind) are defined in COMPILERCONSTANTS.TXT.
Here is sample of using stringlist() to find a delete duplicate records in a codebase type file.
// you would place a TASstringlist on your form called slFileData'
define lCntr,aCntr type R size 10
define BoxCount_hndl type I size 5
define BoxMachHldr type A size 20
define PrcssLine type A size 30
define RecNum type R size 10
define ok type L
btn_del_dupe.click:
lcntr = strings('slFileData','lines',stClear) //Need to clear first..
lCntr = 0
scan @BoxCount_hndl key box_code start '' //reads out data into the stringlist
lCntr = strings('slFileData','lines',stAddLine,box_code+machine_id+str(rcn(BoxCount_hndl),10,0))
ends
if lCntr > 0 // Necessary. If no lines exist in the stringlist the next command would throw an error
Ok = strings('slFileData','lines',stSort)
PrcssLine = strings('slFileData','lines',stGetLine,,1)
BoxMachHldr = mid(PrcssLine,1,20)
for(aCntr;2;lCntr;1)
PrcssLine = strings('slFileData','lines',stGetLine,,aCntr)
if mid(PrcssLine,1,20) = BoxMachHldr
RecNum = val(mid(PrcssLine,21,10))
RCN @BoxCount_hndl rcn RecNum Set
del @BoxCount_hndl nocnf
else
BoxMachHldr = mid(PrcssLine,1,20)
endif
next
endif
ret
Page url: http://www.cassoftware.com/tas/manual/stringlist().htm