A89: Re: Showing Var-Link dialog


[Prev][Next][Index][Thread]

A89: Re: Showing Var-Link dialog




Hi!

> I am trying to make a program that shows the Var-Link dialog, 
> allows the user to select a variable, then returns the name 
> of the chosen variable.  I intend to use this program inside
> of a TI-BASIC program (it would be very useful to be able to
> do this in BASIC, TI was stupid not to put it in). I'm not 
> quite sure how this can be done, however.

Here is a demo (read below about what is wrong in your code):

#include <nostub.h>
#include <all.h>

int _ti89;

char VarBuffer[20]="";

void VarLinkHandler(EVENT *ev)
{
  if(ev->Type=CM_HSTRING)
    strcpy(VarBuffer,HeapDeref(ev->extra.hPasteText));
  EV_defaultHandler(ev);
}

void OpenVarLink(void)
{
  EVENT ev;  
  EVENT_HANDLER OldHandler=EV_captureEvents(VarLinkHandler);
  ev.Type=CM_KEYPRESS;
  ev.extra.Key.Code=4141;         // code of VAR-LNK keypress  
  EV_defaultHandler(&ev);
  EV_captureEvents(OldHandler);
}

void _main(void)
{
  clrscr();
  OpenVarLink();
  printf_xy(0,50,"You picked: %s",VarBuffer);
  ngetchx();
}

> I have tried doing it this way:
> OldHandler = EV_captureEvents(Handler);
> /* Handler is my event handler that is meant to capture 
> CM_KEYPRESS events and save them to a string*/
> OldHandler(&event);  
> /* event is a CM_KEYPRESS event set to 4141, the code of 
> the Var-Link key*/
>
> Is this correct?

No. You need to call EV_defaultHandler instead of OldHandler,
because OldHandler is in fact NULL when there is no any user
handlers installed. From the other side, EV_defaultHandler
calls the TIOS handler which is used for default dispatching
of some common events (see the doc about this function). It 
works independently of which handler is currently installed and
whether it is installed at all.

> My program generates an address error when I run it, before 
> the Var-Link dialog is displayed.

Now you know why.

> Is it illegal to call an event handler when it is not actually
> installed?

Yes. That's reason of introducing EV_defaultHandler.

> I have attatched the complete source code to my program if you
> want to look at it (it's not very well organized, though).

There is yet another problem in your code, in your event handler.
When VAR-LNK applet sends the variable name to the main application,
it uses CM_HSTRING event instead of series of CM_KEYPRESS events
(by the way, CATALOG applet uses CM_STRING instead). See from my
code how you can handle this event.

> Thanks for any help you can provide!

I really hope that this helps.

Zeljko Juric



Follow-Ups: