Page 1 of 1

Trapping events on a ToleAuto object

Posted: Sat Feb 07, 2015 7:36 pm
by reinaldocrespo
Hi.

I usually trap Ole events using :bOnEvent property of TActiveX() object. How can I trap events when the object is created using CreateObject()?

Thank you,


Reinaldo.

Re: Trapping events on a ToleAuto object

Posted: Sat Feb 07, 2015 10:05 pm
by Rick Lipkin
Reinaldo

As they said in the movie Major League .. "Wonder how you feel about the 'Good Ole Number 1'" ( try\Catch ), Also .. you can evaluate oErr on error. :)

Rick Lipkin

Code: Select all

 Try
     oCn  := CREATEOBJECT( "ADODB.Connection" )
 Catch oErr
      MsgInfo( "Could not create the ADO object for connection")
      oDlg:End()
End Try
 

Re: Trapping events on a ToleAuto object

Posted: Sat Feb 07, 2015 11:40 pm
by reinaldocrespo
Thank you, Rick. My question is not how to trap and recover from an error. My question is how to trap the ocx's event. When the object is created using Tactivex():new() you can use bonEvent property to trap and act as you wish anytime an event is triggered by the component. I can't find how to do so when the object is created using create object. Perhaps createobject class can't handle events?

Re: Trapping events on a ToleAuto object

Posted: Sun Feb 08, 2015 5:35 am
by Antonio Linares

Re: Trapping events on a ToleAuto object

Posted: Sun Feb 08, 2015 10:36 pm
by reinaldocrespo
I think it will be easier to try and find out why is TActiveX():New() causing a GFP. If you have a codeJock ocx available you could recreate the gpf with this line:

Code: Select all

      ::oCalexResources := tActiveX():New( ,"Codejock.CalendarResources.13.4.2" ) 
 
I think the gpf happens inside activex.prg new() method at this line:

Code: Select all

      ::hActiveX = CreateActiveX( ::hWnd, cProgID, Self )
 
Can you help?

Thank you.

Re: Trapping events on a ToleAuto object

Posted: Mon Feb 09, 2015 6:55 am
by Richard Chidiak
Reinaldo

This is the code i use for showing multiple schedules , it is working OK

I use Harbour and msvc 2013

Hth

Richard

Code: Select all


METHOD buildMultiSchedule() CLASS TPLANCJ
local oSchedules , ;
      oRes := {} , ;
      n    := 0

IF ! PLANPREF->MULTIPERS  // si pas multi utilisateurs
   RETURN NIL
ENDIF

::objResources := nil
::objResources = createobject("Codejock.CalendarResources.15.0.2")

::oRes1 := nil
::oRes1 = createobject("Codejock.CalendarResource.15.0.2")
::oRes1:SetDataProvider2( "Provider=custom", .T. )

if ! ::oRes1:DataProvider:open()
   ::oRes1:DataProvider:Create()
endif
oSchedules := ::oRes1:DataProvider:Schedules()

DBSELECTAREA("AGPERS")
AGPERS->(ORDSETFOCUS("NOM") )
AGPERS->(DBGOTOP())
n := 0
WHILE ! AGPERS->(EOF())
   IF ! AGPERS->NOPLANNING .AND. AGPERS->AFFICHE # SPACE(5) .AND. n < 11
      with object oSchedules
         :AddNewSchedule( ALLTRIM(AGPERS->AFFICHE) )  // name of the person
         n++
      end
   ENDIF
   AGPERS->(DBSKIP())
ENDDO

IF n = 0
   MSGSTOP("Fichier personnel incohérent pour le planning, veuillez renseigner les critères d'affichage pour chaque personne")
   RETURN NIL
ENDIF
::oRes1:DataProvider:save()

n := 0
AGPERS->(DBGOTOP())
WHILE ! AGPERS->(EOF())
   IF ! AGPERS->NOPLANNING .AND. AGPERS->AFFICHE # SPACE(5) .AND. n < 11
      n++
      IF n = 1
         AADD(ORES,nil)
         ::oRes1:Name = oSchedules:Item(n -1):Name
         ::oRes1:ScheduleIDs:Add(AGPERS->NUMERO) // id of the person
         ::objResources:Add(::oRes1)
       ELSE
         AADD(ORES,createobject("Codejock.CalendarResource.15.0.2"))
         oRes[n]:SetDataProvider( ::oRes1:DataProvider, .F. )
         oRes[n]:Name = oSchedules:Item(n -1):Name
         oRes[n]:ScheduleIDs:Add(AGPERS->NUMERO)

         ::objResources:Add(oRes[n])
      ENDIF
   ENDIF
   AGPERS->(DBSKIP())
ENDDO

FOR n = 1 TO LEN(ORES)
   IF ORES[n] # nil
      oRes[n] := nil // destroy object
   ENDIF
NEXT

::oCalex:SetMultipleResources( ::objResources )
::oCalex:populate()
return nil

 

Re: Trapping events on a ToleAuto object

Posted: Mon Feb 09, 2015 4:37 pm
by reinaldocrespo
Richard,

Thank you very much. Problem solved.

FWIW- I tried to simplify the code. Here it is:

Code: Select all

 
METHOD New() CLASS MpCal
...
   ::aSchedules := ::oSchdls:SaveToArray( { |o| o:id } )

   aTmp := ExecuteSqlScript( "Select label, id from schdl_lbls", .f. )
   aEval( aTmp, { |e,n| hSet( ::hLabels, alltrim( e[ 1 ] ), e[ 2 ] ) } )


   ::BuildPanels()         //two panels -left and right
   ::RegisterOcx()         //Registers the CalendarGlobalSettings ocx and license
   ::BuildCalex()          //actual calendar on the right panel
   ::BuildDatePicker()     //datepicker control on the left
   ::BuildStdDialogs()     //initializes object with various CodeJock standard dialogs to be used

   //work with multiple schedules only when multiple schedules have been created
   IF !EMPTY( ::aSchedules ) ;::SetupForMultiResources() ;ENDIF

   ::oCalex:Populate()
   ::oCalex:RedrawControl()

RETURN SELF


//---------------------------------------------------//
METHOD SetupForMultiResources() CLASS MpCal
local oRes, oData, oErr
local oResCollection2bDestroyed := {} //temporary collection used only to destroy used objects
local cCfgFile


   TRY 
      //collection of schedule resources (mostlikely people or rooms)
      ::oCalexResources := CreateObject( "Codejock.CalendarResources.13.4.2" ) 
   CATCH oErr
      WriteErrorLog( oErr )
      Return NIL 
   END 

   oRes := ::CreateScheduleResource()
   oRes:SetDataProvider2( "Provider=custom", .T. ) 

   oData := oRes:DataProvider
   oData:Open()

   ::oSchedules   := oData:Schedules()    
   ::oSchedules:AddNewSchedule( "Un-Assigned" )

   oRes:Name := ::oSchedules:Item( 0 ):Name
   oRes:ScheduleIDs:Add( 0 )
   ::oCalexResources:Add( oRes )

   AADD( oResCollection2bDestroyed, oRes )

   AEVAL( ::aSchedules, { |e,n| ::oSchedules:AddNewSchedule( e ),;
               AADD( oResCollection2bDestroyed, ::CreateScheduleResource() ),;
               ATAIL( oResCollection2bDestroyed ):SetDataProvider( oData, .T. ),;
               ATAIL( oResCollection2bDestroyed ):Name := e ,; 
               ATAIL( oResCollection2bDestroyed ):ScheduleIDs:Add( n ),;
               ::oCalexResources:Add( ATAIL( oResCollection2bDestroyed ) ) } )
      
      
   ::oCalex:SetMultipleResources( ::oCalexResources )

   AEVAL( oResCollection2bDestroyed, { |e| e := NIL } )
   oResCollection2bDestroyed := NIL    
   
RETURN NIL 


//---------------------------------------------------//
METHOD CreateScheduleResource() CLASS MpCal
local oRes, oErr

   TRY 
      oRes := CreateObject( "Codejock.CalendarResource.13.4.2" )

   CATCH oErr

      WriteErrorLog( oErr )
      MsgInfo( "Missing standard dialogs components" )

   END


RETURN oRes

 

BTW- are you working with events assigned to multiple resources?


Reinaldo.