? [Done] 5.20 B11 Multiple Declare when Events are added

You need some new stunning features ? Tell us here.
luciano
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Mar 09, 2011 8:25 pm

? [Done] 5.20 B11 Multiple Declare when Events are added

Post by luciano »

Please use the two files used in topic:
http://www.purebasic.fr/english/viewtop ... 22&t=56078

Having them both open in the Ide, FD can add events to button using the "event procedure" drop-down;
Add Ok procedure to the OK button, and add TRY procedure to the TRY button and again the TRY procedure to the second TRY button.
In beta 11 it ends with two declarations for the same procedure:

Code: Select all

Global Button_0, Button_1, Button_2, Button_3

Enumeration #PB_Compiler_EnumerationValue
  #MAIN_Window
EndEnumeration

Declare CancelButtonEvent(EventType)
Declare OkButtonEvent(EventType)
Declare TryButtonEvent(EventType)
Declare TryButtonEvent(EventType)

Procedure OpenMAIN_Window(x = 0, y = 0, width = 210, height = 400)
  OpenWindow(#MAIN_Window, x, y, width, height, "SIMPLE TEST", #PB_Window_SystemMenu)
  Button_0 = ButtonGadget(#PB_Any, 30, 20, 130, 70, "CANCEL")
  Button_1 = ButtonGadget(#PB_Any, 30, 110, 130, 70, "OK")
  Button_2 = ButtonGadget(#PB_Any, 30, 200, 130, 70, "TRY")
  Button_3 = ButtonGadget(#PB_Any, 30, 320, 130, 70, "TRY ???")
EndProcedure

Procedure MAIN_Window_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
          CancelButtonEvent(EventType())          
        Case Button_1
          OkButtonEvent(EventType())          
        Case Button_2
          TryButtonEvent(EventType())          
        Case Button_3
          TryButtonEvent(EventType())          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
which of course generates an error ("Procedure already declared").
Last edited by luciano on Thu Aug 29, 2013 9:19 am, edited 1 time in total.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: 5.20 B11 Multiple Declare when Events are added

Post by Polo »

Should be fixed.
luciano
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Mar 09, 2011 8:25 pm

Re: [Done] 5.20 B11 Multiple Declare when Events are added

Post by luciano »

luciano wrote:Please use the two files used in topic:
http://www.purebasic.fr/english/viewtop ... 22&t=56078

Having them both open in the Ide, FD can add events to button using the "event procedure" drop-down;
Add Ok procedure to the OK button, and add TRY procedure to the TRY button and again the TRY procedure to the second TRY button.
In the latest betas (13 and 14) a glitch remains: if you follow these instructions you get an error if you try to preview the form using Compile/Run directly on the form file, no problem if you compile the main .pb file.
Image

I realize that some lines are added to the form code to make the preview possible, but in these lines with fake procedure , the "link procedure" is repeated twice.
No problem if each button has different procedures ( i.e. never repeating)
Since these lines are not inserted in the final .pbf file, no problem when used in the final application, the problem just happens in the preview compilation.

Image

P.s.
Just a further suggestion:
Why don't use "CompilerIf" and "#PB_Compiler_IsMainFile" to automatically exclude added lines when the form file is included in a main file?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: ? [Done] 5.20 B11 Multiple Declare when Events are added

Post by Polo »

I can't reproduce that :oops:
luciano
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Mar 09, 2011 8:25 pm

Re: ? [Done] 5.20 B11 Multiple Declare when Events are added

Post by luciano »

Hi Polo,
I admit that this error is quite tricky and it happens only in strict situations, but I can replicate it constantly even in beta 17, here is the code generated and two screen grabs.
It happens only when two buttons, etc trigger the same event, in this case "TryButtonEvent" ; declare for this procedure is correct, but there is some dummy code generated after the visible code, which contains the declare repeated.
Note that the error messages is referring to lines (45 and 46) which are beyond the visible lines.
This error happens only when you attach events to gadgets using the dropdown at right (e.g events taken from the application main file)

Code: Select all

Global Button_0, Button_1, Button_2, Button_3

Enumeration FormWindow
  #MAIN_Window
EndEnumeration

Declare OkButtonEvent(EventType)
Declare TryButtonEvent(EventType)
Declare CancelButtonEvent(EventType)

Procedure OpenMAIN_Window(x = 0, y = 0, width = 350, height = 300)
  OpenWindow(#MAIN_Window, x, y, width, height, "SIMPLE TEST", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  Button_0 = ButtonGadget(#PB_Any, 30, 20, 130, 70, "CANCEL")
  Button_1 = ButtonGadget(#PB_Any, 30, 110, 130, 70, "OK")
  Button_2 = ButtonGadget(#PB_Any, 30, 200, 130, 70, "TRY")
  Button_3 = ButtonGadget(#PB_Any, 190, 200, 130, 70, "TRY ???")
EndProcedure

Procedure MAIN_Window_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
          CancelButtonEvent(EventType())          
        Case Button_1
          OkButtonEvent(EventType())          
        Case Button_2
          TryButtonEvent(EventType())          
        Case Button_3
          TryButtonEvent(EventType())          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
Image

Image
zohanx747
New User
New User
Posts: 1
Joined: Thu Oct 31, 2013 6:42 am

Re: ? [Done] 5.20 B11 Multiple Declare when Events are added

Post by zohanx747 »

Why don't use "CompilerIf" and "#PB_Compiler_IsMainFile" to automatically exclude added lines when the form file is included in a main file?
Complete set of pass for sure exam questions and wikipedia to provide complete knowledge so you will pass your University of Pennsylvania exam in first try. good luck
Post Reply