Trapping events on a ToleAuto object

Trapping events on a ToleAuto object

Postby reinaldocrespo » Sat Feb 07, 2015 7:36 pm

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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Trapping events on a ToleAuto object

Postby Rick Lipkin » Sat Feb 07, 2015 10:05 pm

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  Expand view

 Try
     oCn  := CREATEOBJECT( "ADODB.Connection" )
 Catch oErr
      MsgInfo( "Could not create the ADO object for connection")
      oDlg:End()
End Try
 
User avatar
Rick Lipkin
 
Posts: 2618
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Trapping events on a ToleAuto object

Postby reinaldocrespo » Sat Feb 07, 2015 11:40 pm

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?
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Trapping events on a ToleAuto object

Postby Antonio Linares » Sun Feb 08, 2015 5:35 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Trapping events on a ToleAuto object

Postby reinaldocrespo » Sun Feb 08, 2015 10:36 pm

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  Expand view

      ::oCalexResources := tActiveX():New( ,"Codejock.CalendarResources.13.4.2" )
 


I think the gpf happens inside activex.prg new() method at this line:

Code: Select all  Expand view

      ::hActiveX = CreateActiveX( ::hWnd, cProgID, Self )
 


Can you help?

Thank you.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Trapping events on a ToleAuto object

Postby Richard Chidiak » Mon Feb 09, 2015 6:55 am

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  Expand view


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

 
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Trapping events on a ToleAuto object

Postby reinaldocrespo » Mon Feb 09, 2015 4:37 pm

Richard,

Thank you very much. Problem solved.

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

Code: Select all  Expand view

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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests