Le forum (ô combien francophone) des utilisateurs de Powerbuilder.
Pages: 1
Créer une fonction globale appelée datastorebox avec le code suivant et comme paramètre le DS à visionner
// ouverture de la fenêtre
OpenWithParm(w_datastore, ads_datastore)
Et voici un export de la fenêtre w_datastore appelée précédement
$PBExportHeader$w_datastore.srw $PBExportComments$Affichage d'une datastore dans une messagebox forward global type w_datastore from window end type type cb_1 from commandbutton within w_datastore end type type dw_1 from datawindow within w_datastore end type type cb_ok from commandbutton within w_datastore end type end forward global type w_datastore from window integer x = 626 integer y = 592 integer width = 2409 integer height = 1228 boolean titlebar = true string title = "Contenu de la DataStore" windowtype windowtype = response! long backcolor = 79741120 cb_1 cb_1 dw_1 dw_1 cb_ok cb_ok end type global w_datastore w_datastore type variables end variables forward prototypes public function string wf_header_name (powerobject apw, string as_colname) public function string wf_premier_tab (ref string as_chaine) end prototypes public function string wf_header_name (powerobject apw, string as_colname);// Retourne le nom de l'objet HEADER associé à la colonne de nom as_colname dans adw_dw STRING ls_liste_objets,ls_objet DATAWINDOW ldw DATASTORE lds CHOOSE CASE apw.TypeOf() CASE datawindow! ldw = apw ls_liste_objets = ldw.Object.DataWindow.Objects DO WHILE Len(Trim(ls_liste_objets)) > 0 ls_objet = wf_premier_tab(ls_liste_objets) IF String(ldw.Describe(ls_objet + ".Band")) = "header" AND Integer(ldw.Describe(as_colname + ".x")) = Integer(ldw.Describe(ls_objet + ".x")) THEN RETURN ls_objet END IF LOOP CASE datastore! lds = apw ls_liste_objets = lds.Object.DataWindow.Objects DO WHILE Len(Trim(ls_liste_objets)) > 0 ls_objet = wf_premier_tab(ls_liste_objets) IF String(lds.Describe(ls_objet + ".Band")) = "header" AND Integer(lds.Describe(as_colname + ".x")) = Integer(lds.Describe(ls_objet + ".x")) THEN RETURN ls_objet END IF LOOP END CHOOSE RETURN "" end function public function string wf_premier_tab (ref string as_chaine);// as_chaine est une chaine de caractères composés d'élements séparés par des tabulations (~t) // Cette fonction renvoie le premier de ces éléments et modifie as_chaine passé par référence LONG ll_pos STRING ls_element ll_pos = Pos(as_chaine,"~t") IF ll_pos > 0 THEN ls_element = Left(as_chaine,ll_pos - 1) as_chaine = RIGHT(as_chaine,Len(as_chaine) - ll_pos) ELSE ls_element = as_chaine as_chaine = "" END IF RETURN ls_element end function on w_datastore.create this.cb_1=create cb_1 this.dw_1=create dw_1 this.cb_ok=create cb_ok this.Control[]={this.cb_1,& this.dw_1,& this.cb_ok} end on on w_datastore.destroy destroy(this.cb_1) destroy(this.dw_1) destroy(this.cb_ok) end on event open;// --------------------------------------------------------------------// // Affichage d'une fenêtre de type MessageBox contenant une DataStore // // syntaxe d'appel : DataStoreBox(ds_datastore) // // --------------------------------------------------------------------// String ls_syntax, ls_header, ls_column Integer i // récupération DataStore en argument DataStore lds_datastore lds_datastore = Message.PowerObjectParm // lecture syntaxe ls_syntax = lds_datastore.Describe('DataWindow.Syntax') //MessageBox('Syntaxe', ls_syntax) // modification nouvelle syntaxe (grid) i = Pos(ls_syntax, 'processing=0') if i > 0 then ls_syntax = Replace(ls_syntax, i, 12, 'processing=1') end if // création dw_1 dw_1.Create(ls_syntax) dw_1.SetRedraw(False) // maj propriétés de dw_1 dw_1.Object.DataWindow.Color = 16777215 dw_1.Object.DataWindow.Grid.Lines = 0 dw_1.Object.DataWindow.Grid.ColumnMove = True dw_1.Object.DataWindow.Selected.Mouse = False dw_1.Object.DataWindow.Header.Color = 12632256 dw_1.Object.DataWindow.Header.Height = 73 dw_1.Object.DataWindow.Detail.Color = 536870912 dw_1.Object.DataWindow.Detail.Height = 73 // maj des headers avec le nom des colonnes + protection for i = 1 to Integer(dw_1.Describe('DataWindow.Column.Count')) ls_header = wf_header_name(dw_1, '#' + String(i)) ls_column = dw_1.Describe('#' + String(i) + '.Name') dw_1.Modify(ls_header + ".Text='" + ls_column + "'") dw_1.Modify('#' + String(i) + '.Protect=1') next // recopie des lignes de la DataStore dans dw_1 lds_datastore.RowsCopy(1, lds_datastore.RowCount(), Primary!, dw_1, 1, Primary!) dw_1.SetRedraw(True) // positionnement focus dw_1.SelectRow(0, False) if dw_1.RowCount() > 0 then dw_1.ScrollToRow(1) dw_1.SelectRow(1, True) end if dw_1.SetFocus() return end event type cb_1 from commandbutton within w_datastore integer x = 2039 integer y = 1024 integer width = 329 integer height = 96 integer taborder = 30 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "&Sauve" boolean default = true end type event clicked;call super::clicked;dw_1.saveas("c:\Winnt\datastore.xls",Excel5!,false) end event type dw_1 from datawindow within w_datastore integer x = 18 integer y = 24 integer width = 2341 integer height = 968 integer taborder = 10 boolean hscrollbar = true boolean vscrollbar = true boolean livescroll = true borderstyle borderstyle = stylelowered! end type event rowfocuschanged;// sélection row courante if currentrow > 0 and dw_1.RowCount() > 0 then dw_1.SelectRow(0, False) dw_1.SelectRow(currentrow, True) dw_1.ScrollToRow(currentrow) end if end event type cb_ok from commandbutton within w_datastore integer x = 1682 integer y = 1024 integer width = 329 integer height = 96 integer taborder = 20 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "&Ok" boolean default = true end type event clicked;// fermeture Close(Parent) end event
Dernière modification par LeCiao (08-11-2007 15:41:12)
Hors ligne
Hors ligne
pépite
Hors ligne
Salut, merci pour cet objet,
ce qui serait encore mieux ce serait d'enlever les références à des objets de ton environnement inconnus chez les autres (ex : u_cb_sauver, f_header_name) ou bien de fournir les export de ces objets aussi (mais là c'est sans fin...)
merci en tout cas
Hors ligne
J'avais pas fais gaffe à ces 2 références.
Du coup j'ai modifié le code PB du premier post pour que se soit indépendant de u_cb_sauver et f_header_name
Dernière modification par LeCiao (06-11-2007 15:23:50)
Hors ligne
hello,
C'est une très bonne initiative, et cela peut tellement être utile que j'essaye de le tester, mais maintenant il y a un appel à f_premier_tab que nous ne connaissons pas......
Merci
Hors ligne
J'ai remodifié. J'ai pas eu le temps de vérifier s'il y en à d'autres mais je continuerais à modifier si besoin
Hors ligne
à priori il n'y avait que ces 2 là. ;-)
Hors ligne
Bonjour,
J'essaye en vain de faire fonctionner cette fenetre.
Je boucle dans la fonction wf_header_name, même si ma datastore ne contient qu'une seule colonne et un seul enregistrement.
Je boucle dans la partie IF String(ldw.Describe(ls_objet ........ et je n'en sort jamais.
Par contre si j'enlève l'appel à cette fonction, ça fonctionne bien.
Pb 10.5.2
Une idée ??
Hors ligne
Oui j'ai une idée
En fait le paramètre de la fonction wf_premier_tab doit être passé par "Reference" au lieu de "value"
Je remodifie le script d'origine
Hors ligne
super, mais oui mais c'est bien sur.
ça marche super
Hors ligne
Pages: 1