Gambas Documentation
Como se hace...
Compilación e instalación
Componentes
Controls pictures
Descripciones del Lenguaje
Developer Documentation
Componentes adicionales de Gambas
Cómo programar componentes en C/C++
Cómo programar componentes en Gambas
Índice Alfabético de la Interfaz de Programación de Gambas
Índice por Categorías de la Interfaz de Programación de Gambas
Name
ARG
BEGIN_METHOD_VOID
BEGIN_PROPERTY
END_METHOD
GB.Add
GB.Alloc
GB.Application.Name
GB.Application.Title
GB.Array.Count
GB.CheckPost
GB.CurrentComponent
GB.Detach
GB.ExistClass
GB.ExistFile
GB.FileName
GB.Free
GB.FreeArray
GB.FreeString
GB.GetClass
GB.GetClassName
GB.GetEnum
GB.GetEvent
GB.GetFunction
GB.GetTempDir
GB.GetTime
GB.GetUnknown
GB.Is
GB.ListEnum
GB.LoadComponent
GB.NewString
GB.NextEnum
GB.Propagate
GB.Push
GB.Realloc
GB.Ref
GB.ReleaseFile
GB.ReturnFloat
GB.ReturnLong
GB.ReturnObject
GB.StopAllEnum
GB.StopEnum
GB.StoreObject
GB.StoreString
GB.StoreVariant
GB.System.Language
GB.Unref
GB.Watch
GB_ARRAY
GB_FLOAT
GB_HOOK_LOOP
GB_HOOK_MAIN
GB_HOOK_POST
GB_HOOK_TIMER
GB_STRING
GB_T_BOOLEAN
GB_T_BYTE
GB_T_DATE
GB_T_FLOAT
GB_T_INTEGER
GB_T_LONG
GB_T_SHORT
GB_T_SINGLE
GB_T_STRING
GB_T_VARIANT
GB_TIMER
PROP
VPROP
Documentacion y Recetas
Documentación del Entorno de Desarrollo
Fragmentos de código
Glosario
Índice del Lenguaje
LÉEME
Licencia del Wiki
Manual del Wiki
Mensajes de Error
Pendiente de traducción
Registrarse
Repositorio de Aplicaciones
Tutoriales
Últimos cambios

GB.Post

void GB.Post ( void (*func)() , long param )

Post a callback routine that will be called at the next event loop.

  • func is the address of the callback.

  • param is a long integer that will be pass to the callback.

Use this function if you can't execute a piece of code immediately.

For example, it is often dangerous to raise an event immediately, as the event handler may indirectly free some memory used by a function higher in the stack. So it is sometimes better to raise the event when you are on top of the event loop.

If you want to use an object in the callback, you must reference it with GB.Ref, to prevent the interpreter destroying it before the callback is called. And do not forget to call GB.Unref once you have finished with the object in the post routine!

For example, GB.Post is used for raising Click events when you select a menu, because raising the event immediately in the QT slot crashes the interpreter !

This function calls the post interpreter hook so that it knows that a new post routine has been registered.

Examples

// This is how menu event are sent in the QT component

static void send_menu_event(CMENU *menu)
{
  GB.Raise(menu, EVENT_Click, 0);
  GB.Unref((void **)&menu);
} 

void CMenu::activated(int id)
{
  CMENU *menu = ... ;

  // Don't send the event immediately
  // GB.Raise(menu, EVENT_Click, NULL);

  GB.Ref(menu);
  GB.Post((void (*)())send_menu_event, (long)menu);
} 

See also