Page 1 of 1

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

Posted: Mon Aug 19, 2013 9:12 am
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").

Re: 5.20 B11 Multiple Declare when Events are added

Posted: Fri Aug 23, 2013 2:40 pm
by Polo
Should be fixed.

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

Posted: Thu Aug 29, 2013 9:18 am
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?

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

Posted: Sat Sep 07, 2013 8:19 pm
by Polo
I can't reproduce that :oops:

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

Posted: Sat Sep 07, 2013 10:36 pm
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

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

Posted: Thu Oct 31, 2013 6:48 am
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?