uf_get_field_label()

Share this topic:



Link to this posting

Postby Ursego » 03 Oct 2013, 15:10

This function gets field name and returns its label (the text of the <field name>_t object). The label is returned without not-alphabetic symbols ("&Name:" is returned as "Name") to be ready for messages. If <field name>_t object doesn't exist (bad practice, but happens) then the function does its best to build a user-friendly label from the field's name ("first_name" ==>> "First Name") to prevent ugly messages.

Your application must have the functions uf_replace_all() (in the same class where you want to adduf_get_field_label() ) and nvl() when you add this function.

Code: Select all
/**********************************************************************************************************************
Acc:   public
-----------------------------------------------------------------------------------------------------------------------
Dscr:   Gets field name and returns its label (the text of the "<field name>_t" object).
      The label is returned without not-alphabetic symbols ("&Name:" is returned as "Name") to be ready for messages.
      If "<field name>_t" object doesn't exist (bad practice, but happens) then the function does its best to build
      a user-friendly label from the field's name ("first_name" ==>> "First Name") to prevent ugly messages.
-----------------------------------------------------------------------------------------------------------------------
Arg:   adw - DataWindow to search in
      as_field_name
-----------------------------------------------------------------------------------------------------------------------
Ret:   string
-----------------------------------------------------------------------------------------------------------------------
Log:   01may2012 Michael Zuskin   Initial version from http://forum.powerbuilder.us/viewtopic.php?f=4&t=104
**********************************************************************************************************************/
string ls_field_label

ls_field_label = adw.Describe(as_field_name + "_t.Text")
if iin(ls_field_label, {"!", "?"}) /* there is NO text object named "<field name>_t" */ then
   // Try to save the situation and return something which can be used as the column's label:
   ls_field_label = as_field_name
   uf_replace_all(ref ls_field_label, "_", " ") // "first_name" ==>> "first name"
   WordCap(ls_field_label) // "first name" ==>> "First Name"
else // text object, named "<field name>_t", exists
   // Remove semicolon which exsist in many labels on free-form DW:
   if Right(ls_field_label, 1) = ":" then
      ls_field_label = Left(ls_field_label, Len(ls_field_label) - 1)
   end if
   // Remove ampersands which mark hot-key symbols, displayed to user underlined:
   uf_replace_all(ref ls_field_label, "&&", this.ClassName()) // save double-ampersand (which is displayed as one) from removing by next line
   uf_replace_all(ref ls_field_label, "&", "")
   uf_replace_all(ref ls_field_label, this.ClassName(), "&") // restore the saved ampersand (display it as one)
   // Remove other not-alphabetic symbols which can appear in the label:
   uf_replace_all(ref ls_field_label, "~n~r", " ")
   uf_replace_all(ref ls_field_label, "~r~n", " ")
   uf_replace_all(ref ls_field_label, "~n", " ")
   uf_replace_all(ref ls_field_label, "~r", " ")
   uf_replace_all(ref ls_field_label, "~"", "")
end if

return ls_field_label
User avatar
Ursego
Site Admin
 
Posts: 112
Joined: 19 Feb 2013, 20:33

Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 2 guests


uf_get_field_label()

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





free counters

eXTReMe Tracker