Skip to content

Simpol Collections

Forums Forums SIMPOL Programming Simpol Collections

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #269

    Hi folks, I am new to this forum therefore please be kind. I would like to share some thoughts with you about a SIMPOL type which I am using a lot now in my code and speeded up my SIMPOL web application. It is a Collections which I have built mainly to have a foreach loop integrated with it. Please let me know if something can be improved. You are free to use it but it would be nice having your feedback (bad or good) Copy and paste the code below and run it. ENJOY!!!! type ListCollection export embed integer count reference array list resolve function delByKey function delByIndex function add //function clearall ;// not implemented function foreach end type function ListCollection.foreach(ListCollection me, function func, type(*) return) integer i i = 1 if me.count > 0 while i <= me.count //if me.list["value", i] !@= .nul func(me.list["value", i], return) //end if i = i + 1 end while i > me.count end if end function function ListCollection.add(ListCollection me, anyvalue key, type(*) value) if value !@= .nul and key !@= .nul me.count = me.count + 1 if value.type == “string” or value.type == “integer” or value.type == “number” or value.type == “boolean” or value.type =@= blob me.list[key] = value me.list[“value”, me.count] = value else me.list[key] =@ value me.list[“value”, me.count] =@ value end if me.list[“key”, me.count] = key end if end function function ListCollection.delByIndex(ListCollection me, integer idx) if me.list[“value”,idx] !@= .nul me.list[“value”,idx] =@ .nul me.count = me.count – 1 end if end function function ListCollection.delByKey(ListCollection me, anyvalue key) if me.list[key] !@= .nul me.list[key] =@ .nul me.count = me.count – 1 end if end function function ListCollection.new(ListCollection me) me.list =@ array.new() me.count = 0 end function me type StringCollection(ListCollection) export reference ListCollection list resolve function add function collection2Array end type function StringCollection.new(StringCollection me) me.list =@ ListCollection.new() end function me function StringCollection.add(StringCollection me, anyvalue key, string value) me.list.add(key, value) end function function StringCollection.collection2Array(StringCollection cString) information “[simpol::return::string]” integer iC string sName, sTmp array aList aList =@ array.new() iC = 1 while iC <= cString.count sName = cString["key", iC] sTmp = cString["value", iC] if sTmp !@= .nul aList[0, iC] = sName ;// index aList[1, iC] = sTmp ;// row end if iC = iC + 1 end while aList[] = iC - 1 end function aList function main() string t integer i, tot i = 0 tot = 20 t = '' StringCollection list list =@ StringCollection.new() while i <= tot i = i + 1 t = .tostr(i,10) list.add(i,t) end while string message message = '' list.foreach(test, message) end function message function test(string item, string message) message = message + "{a}{d}" + item end function

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.