Page 34 of 39

Posted: Fri Mar 13, 2009 5:14 pm
by GeBonet
Hello,

I modified the original code like this ...
This works very wel unless the line I usually 95-103 ... Compiler error ... ?
Someone has a solution? Or this form does not work?
Too many COMAT call ???
Thank you for your answer ...
(Excuse my English, I am Belgian and speak French ...)

Code: Select all

;/////////////////////////////////////////////////////////////////////////////////
;***COMate***  COM automation through iDispatch.
;*====================================
;*
;*MSComctLib_TreeCtrl demo 2 (with events!) - by ???
;*This demo may not run correctly on XP with service pack 2. This is a known issue!
;/////////////////////////////////////////////////////////////////////////////////
;
;    I have try with XP SP3....... Like this is OK   But Whis the line 95---> 103 on... Than, ERROR with memory... I thing !
;  
Global Rep$
   
    Rep$=GetPathPart(ProgramFilename())  
    SetCurrentDirectory(Rep$)
    
    IncludePath "..\..\"
    XIncludeFile "COMate.pbi"

Enumeration ; Relationship
    #tvwFirst
    #tvwLast
    #tvwNext
    #tvwPrevious
    #tvwChild
EndEnumeration

Define.COMateObject treeViewObject, treeNodeObject

;/////////////////////////////////////////////////////////////////////////////////
;The following is our event callback for our ActiveX object.
;The 'Object' parameter will contain the COMate object upon which was used the \SetEventHandler() method; in our case it will point
;to our treeViewObject.
Procedure EventProc(Object.COMateObject, eventName$, parameterCount)
    If eventName$ = "NodeClick"
        ;Here we set the string gadget's text to match the text of the selected item.
        SetGadgetText(1, Object\GetStringEventParam(1))
    EndIf
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
;The following utility adds a new node to the tree.
Procedure.l TreeviewNodesAdd(treeViewObject.COMateObject, Relative.s = "", Relationship.l = -1, key.s = "", Text.s = "")
    Protected treeNodeObject.COMateObject
    treeNodeObject = treeViewObject\GetObjectProperty("Nodes\Add('" + Relative + "', " + Str(Relationship) + ", '" + key + "', '" + Text + "')")
    ProcedureReturn treeNodeObject
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


If OpenWindow(0, #PB_Ignore, #PB_Ignore, 450, 600, "COMate - TreeView ActiveX demo 2 (with events!)")    

  StringGadget(1, 5, 5, 440, 20,"")
  
  treeViewObject = COMate_CreateActiveXControl(5, 30, 440, 565, "MSComctlLib.TreeCtrl")

    If treeViewObject
        treeViewObject\SetProperty("HideSelection = #False")
        treeViewObject\SetProperty("LabelEdit = 1") ;Change to zero for automatic one-click editing.
    
        ; Ajout du NOEUD SOURCE.....
          treeNodeObject = treeViewObject\GetObjectProperty("Nodes\Add")
          treeNodeObject\SetProperty("Text = 'Root'")
          treeNodeObject\SetProperty("Key = 'root'")
          treeNodeObject\SetProperty("Expanded = #True")
            treeNodeObject\Release()
        ;
        ; Ajout du Premier SOUS Noeud 
          treeNodeObject = TreeviewNodesAdd(treeViewObject, "root", #tvwChild, "animals", "Animals")
          treeNodeObject\SetProperty("Expanded=#True")
            treeNodeObject\Release()
                ;
                ; Ajout du Premier SOUS/ Sous Noeud 
                  treeNodeObject = TreeviewNodesAdd(treeViewObject, "animals", #tvwChild, "cats", "Chats")
                    treeNodeObject\Release()
                    
                          ;  Ajout du Troisième SOUS/ Sous Noeud /sous Noeud 
                            treeNodeObject = TreeviewNodesAdd(treeViewObject, "cats", #tvwChild, "jouet", "Jouets")
                            treeNodeObject\Release()
                          ;  ; Ajout du Troisième SOUS/ Sous Noeud /sous Noeud 
                            treeNodeObject = TreeviewNodesAdd(treeViewObject, "cats", #tvwChild, "Vaccins", "Vaccins")
                            treeNodeObject\Release()
                            ; Ajout du Troisième SOUS/ Sous Noeud /sous Noeud 
                            treeNodeObject = TreeviewNodesAdd(treeViewObject, "cats", #tvwChild, "Vétérinaire", "Vétérinaire")
                            treeNodeObject\Release()
                            
                ; Ajout du Second SOUS/ Sous Noeud 
                  treeNodeObject = TreeviewNodesAdd(treeViewObject, "animals", #tvwChild, "dogs", "Chiens")
                    treeNodeObject\Release()
                    ; ***********************************************************************************************************************       
                    ; <<<<<<<<<<<<<< Here if you ativate line below, than the compiler have some problems...>>>>>>>>>>>
                    ;                                  Is above or below .... Not all two... !!!   Wy ????????????       
                    ; ***********************************************************************************************************************                           
                          ; Ajout du Troisième SOUS/ Sous Noeud /sous Noeud 
                          ;-  treeNodeObject = TreeviewNodesAdd(treeViewObject, "dogs", #tvwChild, "jouet", "Jouets")
                          ;-  treeNodeObject\Release()
                          ; Ajout du Troisième SOUS/ Sous Noeud /sous Noeud 
                          ;-   treeNodeObject = TreeviewNodesAdd(treeViewObject, "dogs", #tvwChild, "Vaccins", "Vaccins")
                          ;-   treeNodeObject\Release()
                          ; Ajout du Troisième SOUS/ Sous Noeud /sous Noeud 
                          ;-   treeNodeObject = TreeviewNodesAdd(treeViewObject, "dogs", #tvwChild, "Vétérinaire", "Vétérinaire")
                          ;-   treeNodeObject\Release()
        ;
        ; Ajout du Second SOUS Noeud 
          treeNodeObject = TreeviewNodesAdd(treeViewObject, "root", #tvwChild, "cars", "Cars")
          treeNodeObject\SetProperty("Expanded=#True")
            treeNodeObject\Release()
                ;
                ; Ajout du Premier SOUS/ Sous Noeud du second SOUS... 
                  treeNodeObject = TreeviewNodesAdd(treeViewObject, "cars", #tvwChild, "ferrari", "Ferrari")
                    treeNodeObject\Release()
                ; Ajout du Second SOUS/ Sous Noeud
                  treeNodeObject = TreeviewNodesAdd(treeViewObject, "cars", #tvwChild, "lamborghini", "Lamborghini")
                    treeNodeObject\Release()
        ; 
        ; Data.s "0 ROOT", "Gestion d'un Budget" 
        ; Data.s "1 POST", 2
        ;   Data.s,"1 ENTREE"
        ;       Data.s "1 S-POST", "8"
        ;       Data.s, "Traitement 1","Traitement 2","Allocations 1","Allocations 2", "Allocations 3","Rente 1","Rente 2","Rente 3"
        
        ;   Data.s, "2 SORTIE"
        ;       Data.s "2 S-POST","11"
        ;       Data.s "Alimentations","Habillement","Santé","Hygiène et Entretient","Equipement et Entretient Maison"
        ;       Data.s "Electro Et Mobiliers","Matériel Bureaux et Librairie","Frais Scolaire et Sportif","Sorties et Divers","Animaux et Jardins"
        ;       Data.s  "FIN"
        ;   
        ;   Règle   :  Dès la deuxième lecture, quand le nom d'une rubrique devient un titre on augmente de niveau.... 
        ;   ---------               
        ; 
        ;   Pour le ROOT ou Premier noeud  ===> Nom de la source ===> BUDGET par exemple 
        ;           ----------------------------------------------------------------------------------------------------------------
        ;           pour les Sous Noeud principaux ==le 1 ====> Ici Cathégories.. ======> ENTREE 
        ;                   ---------------------------------------------------------------------------------------------------------
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Traitement 1
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Traitement 2
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Allocations 1
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Allocations  2
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Allocations  3
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Rente   1
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Rente   2
        ;                    Pour les entrées ou Sous Noeud 1 du sous Noeud ==========> Rente   3
        ;           ----------------------------------------------------------------------------------------------------------------
        ;           pour les Sous Noeud principaux ==le 2 ====> Ici Cathégories.. ======> SORTIE
        ;                   ---------------------------------------------------------------------------------------------------------
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Alimentations
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Habillement
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Santé 
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Hygiène et Entretient
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Equipement et Entretient Maison
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Electro Et Mobiliers 
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Matériel Bureaux et Librairie
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Frais Scolaire et Sportif
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Sorties et Divers 
        ;                    Pour les entrées ou Sous Noeud 2 du sous Noeud ==========> Animaux et Jardins
        ; ---------------------------------------------------------------------------------------------------------------------------------------
        ;  Initialise le Callback. d'evenement 
        ;
          treeViewObject\SetEventHandler(#COMate_CatchAllEvents, @EventProc())
        ;
        Repeat
            Select WaitWindowEvent()
                Case #PB_Event_CloseWindow
                    Break
                Case #PB_Event_Gadget
                    ;
                    Select EventGadget()
                        Case 1
                            If EventType() = #PB_EventType_Change
                                treeNodeObject = treeViewObject\GetObjectProperty("SelectedItem")
                                ;
                                If treeNodeObject
                                    NewNodeText$=GetGadgetText(1)
                                    treeNodeObject\SetProperty("Text = '" + NewNodeText$ + "'")
                                    treeNodeObject\Release()
                                EndIf
                                ;
                            EndIf
                    EndSelect
                    ;    
            EndSelect
        ForEver
        treeViewObject\Release()
    Else
        MessageRequester("COMate - TreeView ActiveX demo", "Couldn't create the ActiveX control!")
    EndIf    
    CloseWindow(0)

EndIf
End

Posted: Fri Mar 13, 2009 6:34 pm
by srod
You're duplicating keys!

In line 95 you have the key "jouet"; a key you have used before!

Posted: Fri Mar 13, 2009 6:44 pm
by GeBonet
It's true ... I missed it ...
I need new glasses ..
Result of copy paste ...

Thank you and excuse the inconvenience

Posted: Fri Mar 13, 2009 6:47 pm
by srod
Truth be told that it is not a very good demo program, as there is very little error checking in it. I should really rectify that! You should of course be checking that treeNodeObject is non-zero every time you attempt to add new nodes etc. Attempting to invoke some method or other on a non-existant object will cause a crash... as it did with your code! :)

Posted: Fri Mar 13, 2009 7:17 pm
by GeBonet
Ok, no problem ... A demo is a demo and not a truth ...
My goal is a test to try to put parameters in precisely the links of the nodes to make it dynamic.
And thus able to increase or remove links without having to enter the code but asking from files or keyboard input
Once I found something interesting, I sent you ...
And thank you again for your help
.

Posted: Sat Mar 14, 2009 8:02 pm
by SFSxOI
Finally finished my little unattended windows update project. Sucessfully deployed it, it works great! Posted simplified version in the tips and tricks > http://www.purebasic.fr/english/viewtop ... 392#280392

Posted: Mon Mar 16, 2009 11:19 am
by Kwai chang caine
SROOOOODDDDDD !!!!!!
It's the nightmare of your life :D

Like i have promise to you.....i have run on my PC, no say hello at my numerous colleagues, no sit down on my chair :D

Like a medicament i have paste your splendid code, and the miracle is create before my round eyes :shock:

My PC not resist at your transfusion of PureCOMate :D
And the key appears 8)

Immediatelly..... KCC is go on his desk, and dance like a "Tahician", so much he is happy :D

Image

Well.....now i go to explain to my boss, how i have exploded his desk and fall down his computer with my feet :? :oops:

Thank you very very much SROD 8)
That the gods protect you 8)

Posted: Mon Mar 16, 2009 11:25 am
by srod
Right, no more 'cowpat' style VB translations please! :wink:

Posted: Mon Mar 16, 2009 12:17 pm
by Kwai chang caine
srod wrote:Right, no more 'cowpat' style VB translations please! :wink:
Yes yes, i promise to you..... :D
Finally...i try of promise to you, is the true sentence :oops:

But perhaps you allow me, to present to you, a "HorsePat" (Dung) of visual basic, for the next time :roll: :lol:

Posted: Mon Mar 16, 2009 12:24 pm
by srod
Now 'horsepat' is perfectly acceptable; that is an altogether better quality of 'pat'!

:)

Posted: Mon Mar 16, 2009 1:51 pm
by Kwai chang caine
You can to be proud of your student...
Because you don't believe your eyes when you read that :

Thanks to you...i have find the next COM instruction for my code alone, like a grow, with my 2 nerve cell, and without disturb MASTER SROD :D
And it's a miracle...that's works :shock:

You must search.... if you have not loose knowledge on the ground.....because perhaps i have found and keep it for me !!! :lol:

The knowledge is the only thing, who increase when it is shared 8)

Citation of Sacha Boudjema in french :
"La connaissance est la seule chose qui s'accroit lorsqu'on la partage"

srod wrote:Now 'horsepat' is perfectly acceptable; that is an altogether better quality of 'pat'!
:)
Ok ok MASTER !!!! your desire is like order for KCC !!! 8)

Image

Again thanks for your great kindness 8)

Posted: Tue Mar 17, 2009 8:35 pm
by CNESM
Hi,

the last weeks i worked with COMmate and i like this pbi very mutch. Now i had a little problem and i hope somebody can help me :-)

I try to add a personel commandbar to the opend/running excel application with personal buttons, personal icons etc. Closer i want to find out, when the user use one of my created buttons of this commendbar. To create the commenbar with COMmate is not the problem. The problem i have is, that i dont know how can i find out, when ther user put one of my buttons. For example: If the user use the button "New" in the example down below i want to open a purebasic window.

In VBA it goes like this:

In VBA you have the possibility to give every created button a personal "OnAction"- Procedure:

Code: Select all

    Set btnNew = Application.CommandBars("myCommendBar").Controls.Add(Type:=msoControlButton)
        With btnNew
            .Style = msoButtonIconAndCaption
            .FaceId = 18
            .Caption = "New"
            .TooltipText = "Create new query"
            .BeginGroup = True
            .OnAction = "funcCreateNewQuery"
    End With

That means: If the user put the button "new", Excel will execute the "OnAction" Procedure "funcCreateNewQuery".

I hope somebody can help me and you understand what i want:

Enclosed my first test in purebasic with the created commenbar but without any event handling when the user use the button "new"or close the excel apllication.

Code: Select all

XIncludeFile "C:\Users\Zu\Desktop\COMate_Residents.pbi"
XIncludeFile "C:\Users\Zu\Desktop\COMate.pbi"

objExcel.COMateObject
objCommandBars.COMateObject
objCommandBarsButton1.COMateObject
objCommandBarsButton2.COMateObject
objCommandBarsButton3.COMateObject

Define.COMateObject ExcelObject, WorkBook

Procedure myEventCallback(object.COMateObject, eventName.s, parameterCount)
 Debug eventName.s
 Debug object.COMateObject
Debug parameterCount

EndProcedure

objExcel=COMate_GetObject("", "Excel.Application")
If objExcel=0
  objExcel=COMate_CreateObject("Excel.Application")
EndIf 

 
If objExcel

  If objExcel\SetProperty("Visible = #True") = #S_OK

    objExcel\Invoke("CommandBars('My Commendbar')\Delete")
    objCommandBars=objExcel\GetObjectProperty("CommandBars\Add('My Commendbar', 1, 0, 0)") ;1=Position , 0=MenuBar , 0=Temporary 
    
       If objCommandBars
          objCommandBars\SetProperty("Left = 0")
          objCommandBars\SetProperty("Visible = #False")
     
          objCommandBarsButton1=objExcel\GetObjectProperty("CommandBars('My Commendbar')\Controls\Add(1)")
          If objCommandBarsButton1
            objCommandBarsButton1\SetProperty("Style = 3") ; 3=msoButtonIconAndCaption
            objCommandBarsButton1\SetProperty("FaceId = 18")
            objCommandBarsButton1\SetProperty("Caption = 'New'")
            objCommandBarsButton1\SetProperty("TooltipText = 'New booking document'")
            objCommandBarsButton1\SetProperty("BeginGroup = #True")
            ;objCommandBarsButton1\SetProperty("OnAction = 'NewBookingDocument'")
            
            objCommandBarsButton2=objExcel\GetObjectProperty("CommandBars('My Commendbar')\Controls\Add(1)")
            If objCommandBarsButton2
              objCommandBarsButton2\SetProperty("Style = 3") ; 3=msoButtonIconAndCaption
              objCommandBarsButton2\SetProperty("FaceId = 548")
              objCommandBarsButton2\SetProperty("Caption = 'Functions'")
              objCommandBarsButton2\SetProperty("TooltipText = 'Different functions'")
              objCommandBarsButton2\SetProperty("BeginGroup = #True")
              ;objCommandBarsButton2\SetProperty("OnAction = 'DifferentFunctions'")

              objExcel\SetProperty("CommandBars('My Commendbar')\Visible = #True")
              HRESULT=objCommandBars\SetEventHandler(@myEventCallback())
                
              If HRESULT
              Else
                Debug "error5"
              EndIf
              
            Else
              Debug "error4"
            EndIf
            
          Else
            Debug "error3"
          EndIf
    

       Else
        Debug "error2"
        EndIf
     
   Else
    Debug "error7"
   EndIf

  
Else
  Debug "error1"
EndIf

MessageRequester("","")


objExcel\Release()
; IDE Options = PureBasic 4.30 (Windows - x86)
; CursorPosition = 79
; FirstLine = 33
; Folding = -
; EnableXP

Posted: Wed Mar 18, 2009 12:17 am
by srod
Well the .OnAction property is referring to either a named macro or a VBA function neither of which are present in your worksheet and so I cannot see how you can get this to work in this way?

You will probably need to somehow add a macro to the underlying workbook.

I think it unlikely that you will be able to attach an event sink to an out of process server either; even if it is correctly marshalled. At least my attempts have failed to receive any events. You would probably need to embed the worksheet in a webgadget or some such.

Posted: Wed Mar 18, 2009 4:44 pm
by CNESM
Hello srod,

exactly, that's the problem: How can i receive any events of the commendbar, when the commenbar is not a part of my application? In the normal way it should work with a simple callback but the problem is, that the commendbar is not in my purebasic window and the buttons seems only to work with the OnAction property thats like a link to an external procedure. Do you think there is any way to get/callback the messages from the commendbar in my purebasic application?

I tested to generate the neccesary macro by realtime in the underlying workbook. That's worked but is not a good way to do that. I want to handle all things in and with purebasic. To generate the macro take me away from this statement because i have to write my program in VBA and thats not good, becase some other project are already finished in pb and this is the last projekt, that will be a big part of this application family :-)

Maybe you or anyone else could help by this problem. Have anybody another idea to handle the message from the commendbar?

Posted: Wed Mar 18, 2009 7:46 pm
by srod
From what I've seen, it is not a question of catching any events on this occasion, but of setting up a macro etc. Can you add a macro to an Excel workbook through COMate?

As I say, if you wish to catch some events then I would guess that you'll have to load the worksheet into a web gadget or an instance of IE. You can certainly catch events from an IE instance as I've done this myself.

Quite why I cannot receive them from an instance of Excel I am unsure? Perhaps the level of marshalling involved is far deeper with the IE case?