[Gambas-user] tags

Fabien Bodard gambas.fr at ...626...
Sat Nov 14 17:19:38 CET 2009


the same  but with a collection to share the result

2009/11/14 Doriano Blengino <doriano.blengino at ...1909...>:
> Jean-Yves F. Barbier ha scritto:
>> Doriano Blengino a écrit :
>> ....
>>
>>> About "recover any kind [...] from into a loop", I don't understand.
>>> Perhaps you want to scan all the controls residing on a form - there is
>>> the Controls[] property for that. Or you want to stream out all the
>>>
>>
>>
> I am suspecting you are transferring data from and to a database...
> don't know why  I suspect...
>
> May be the following routines can act as a base, if this is your duty.
>
> The first one, load_record(), takes a container and a Result as
> parameters, and fills every control in the container with the
> corresponding data from the current record of Result. In the container,
> relevant controls must be named "edDBxxxx", where "xxxx" is the name of
> the field from database; other controls are ignored.
>
> For every kind of control different code is used, so you can use
> specialized controls, as I did with TDbCalcBox, which is a special
> control of mines.
>
>
>    ' transfers a record from a result to a page; TRUE if error
>    PUBLIC SUB load_record(hCont AS Container, res AS Result) AS Boolean
>      DIM obj AS Object
>
>      FOR EACH obj IN hCont.Children
>        IF obj.name LIKE "edDB*" THEN
>          SELECT Lower(object.Type(obj))
>            CASE "textbox", "tdbsimplebox"
>            TRY obj.text = res[Mid(obj.name, 5)]
>
>            CASE "tdbcalcbox"
>            obj.text = "0"
>            TRY obj.text = utils.formatdecimal(res[Mid(obj.name, 5)],
>    "#,0", obj.decimals)
>
>            CASE "tdbdatebox"
>            IF dateformat = "" THEN calculate_dateseparator
>            obj.text = ""
>            ' TRY obj.text = Format(res[Mid(obj.name, 5)], dateformat)
>            TRY obj.text = canonicaldate(Format(res[Mid(obj.name, 5)],
>    gb.GeneralDate))
>
>            CASE "checkbox"
>            obj.value = FALSE
>            IF res[Mid(obj.name, 5)] THEN obj.value = TRUE
>
>            CASE "label"
>            obj.text = "?"
>            TRY obj.text = res[Mid(obj.name, 5)]
>
>          END SELECT
>        ENDIF
>      NEXT
>      RETURN FALSE
>
>      CATCH
>      Message.Error("Errore " & error.Text & " in " & error.Where)
>      RETURN TRUE
>    END
>
> This is the counterpart of the previous, to write a record out to a
> database.
>
>
>    ' transfers a record from page to database; TRUE if error
>    PUBLIC SUB save_record(hCont AS Container, recmod AS Result) AS Boolean
>      DIM obj AS Object
>      DIM st AS String
>
>      FOR EACH obj IN hCont.Children
>        IF obj.name LIKE "edDB*" THEN
>          SELECT Lower(object.Type(obj))
>            CASE "textbox", "tdbsimplebox"
>            recmod[Mid(obj.name, 5)] = obj.text
>
>            CASE "tdbcalcbox"
>            recmod[Mid(obj.name, 5)] = utils.formatted2float(obj.text)
>
>            CASE "tdbdatebox"
>            st = canonicaldate(obj.text)
>            IF st <> "" THEN recmod[Mid(obj.name, 5)] = Val(st)
>
>            CASE "checkbox"
>            recmod[Mid(obj.name, 5)] = obj.value
>
>          END SELECT
>        ENDIF
>      NEXT
>      recmod.Update
>      RETURN FALSE
>
>      CATCH
>      Message.Error("Errore " & error.Text & " in " & error.Where)
>      RETURN TRUE
>    END
>
> This last one fills a grid, displaying a Result in tabular form.
>
>    ' prepare and fill a grid with data from a result
>    ' columns are defined as "dbfield/title!width"
>    ' dbfield is the field name in recordset
>    ' title is the column title; if absent, same as dbfield
>    ' width is the column width. If absent, equally spaced columns are used
>    ' example: "id/Unique code!120
>    ' columns are modified only if col[0].text is empty
>    PUBLIC SUB fill_rec_grid(gvDB AS GridView, Columns AS String, res AS
>    result)
>      DIM i, k, width AS Integer
>      DIM fields AS String[]
>      DIM st, title AS String
>      DIM managecols AS Boolean
>
>      managecols = TRUE
>      IF gvdb.Columns.Count THEN managecols = gvdb.Columns[0].Text = ""
>
>      fields = Split(columns, ",", "", FALSE)
>      gvDB.Columns.Count = fields.Count
>
>      FOR i = 0 TO fields.count - 1
>        st = fields[i]
>        k = InStr(st, "!")
>        width = gvdb.Width \ fields.Count   ' default
>        IF k THEN
>          width = Val(Mid(st, k + 1))
>          st = Left(st, k - 1)
>        ENDIF
>        IF managecols THEN gvdb.Columns[i].Width = width
>        k = InStr(st, "/")
>        IF k THEN
>          title = Mid(st, k + 1)
>          st = Left(st, k - 1)
>        ELSE
>          title = st
>        ENDIF
>        IF managecols THEN
>          gvdb.Columns[i].text = title
>          title = Upper(Left(title, 1)) & Mid(title, 2)
>        ENDIF
>        fields[i] = st
>      NEXT
>      gvDB.Rows.Count = res.Count
>
>      FOR i = 0 TO res.Count - 1
>        res.MoveTo(i)
>        FOR k = 0 TO fields.Count - 1
>          title = fields[k]
>          TRY st = res[title]
>          IF NOT ERROR THEN
>            width = res.Fields[title].Type
>            ' find correct formatting
>            SELECT width
>              CASE 8
>                ' date field
>                st = Format(res[title], gb.GeneralDate)
>                gvDB[i, k].Text = " " & st
>
>              CASE 7
>                ' float - align right
>                st = " " & res[title]
>                WHILE gvdb.font.Width(st) + 8 < gvdb.Columns[k].Width
>                  st = " " & st
>                WEND
>                gvDB[i, k].Text = Mid(st, 2)
>
>              DEFAULT
>                ' normal field
>                ' do NOT format! Sometimes text is used as database key
>                TRY gvDB[i, k].Text = res[title]
>            END SELECT
>          ENDIF
>        NEXT
>      NEXT
>    END
>
> If this is not what you needed, simply ignore it - but may be you can
> see something useful.
>
> Regards,
>
> --
> Doriano Blengino
>
> "Listen twice before you speak.
> This is why we have two ears, but only one mouth."
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: analyserecursive-0.0.1.tar.gz
Type: application/x-gzip
Size: 8265 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20091114/f9b2c9d5/attachment.bin>


More information about the User mailing list