discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Determining which button was clicked using it's id attribute


From: Fred Kiefer
Subject: Re: Determining which button was clicked using it's id attribute
Date: Sat, 20 Nov 2010 13:04:42 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.15) Gecko/20101026 SUSE/3.0.10 Thunderbird/3.0.10

Hi Pal,

just like your compiler I have no idea what you mean by the "id" of the
button :-)

A button, like many other GUI elements in OpenStep, may have a tag
assigned to it. This can be done in Gorm (or InterfaceBuilder if you are
working on MaOSX) or in code. The tag is an integer value and if you are
careful to use an unique value per button, this can be easily used in a
switch statement.

Hope this helps
Fred


Am 19.11.2010 20:40, schrieb Csanyi Pal:
> Jason Lincoln <jlincoln@yahoo.com> writes:
> 
>> In your case, could you get the button's title to determine which one
>> sent the action message? 
> 
> I can, but the button titles is not good for me because I have on my
> application's GUI 8 buttons (toggle type all) and these buttons all has
> title '1' and alternate title '0', but it's 'id' attributes are
> different.
> 
> See my code bellow:
> 
> [code]
> - (void) DPbitSetReset: (id)sender
> {
> 
>   NSSound *DPbitReset = [NSSound soundNamed: @"DPbitReset.wav"];
>   NSSound *DPbitSet = [NSSound soundNamed: @"DPbitSet.wav"];
>   NSString *ButtonId = [sender id];
> 
>   // Whether the button state is 1 or 0?
>   if ([sender state] == 1)
>      {
>        // Play the bit set sound
>        [DPbitSet play];
> 
>        // Which bit on Data Port?
>        if ([ButtonId isEqualToString: @"DPb0sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 0"];
>        }
>        if ([ButtonId isEqualToString: @"DPb1sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 1"];
>        }
>        if ([ButtonId isEqualToString: @"DPb2sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 2"];
>        }
>        if ([ButtonId isEqualToString: @"DPb3sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 3"];
>        }
>        if ([ButtonId isEqualToString: @"DPb4sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 4"];
>        }
>        if ([ButtonId isEqualToString: @"DPb5sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 5"];
>        }
>        if ([ButtonId isEqualToString: @"DPb6sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 6"];
>        }
>        if ([ButtonId isEqualToString: @"DPb7sr"]);
>        {
>        [StatLine setStringValue: @"write logical 1 to the data port bit 7"];
>        }
>      }
> 
>   else if ([sender state] == 0)
>      {
>         // Play the bit reset sound
>        [DPbitReset play];
> 
>        // Which bit on Data Port?
>        if ([ButtonId isEqualToString: @"DPb0sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 0"];
>        }
>        if ([ButtonId isEqualToString: @"DPb1sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 1"];
>        }
>        if ([ButtonId isEqualToString: @"DPb2sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 2"];
>        }
>        if ([ButtonId isEqualToString: @"DPb3sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 3"];
>        }
>        if ([ButtonId isEqualToString: @"DPb4sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 4"];
>        }
>        if ([ButtonId isEqualToString: @"DPb5sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 5"];
>        }
>        if ([ButtonId isEqualToString: @"DPb6sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 6"];
>        }
>        if ([ButtonId isEqualToString: @"DPb7sr"]);
>        {
>        [StatLine setStringValue: @"write logical 0 to the data port bit 7"];
>        }
>      }
> }
> [/code]
> 
> If I compile the application with 'make' I get error messages:
> This is gnustep-make 2.4.0. Type 'make print-gnustep-make-help' for help.
> Making all for app LPT_Interface...
>  Compiling file MainController.m ...
> MainController.m:120: error: expected ‘{’ before ‘-’ token
> MainController.m: In function ‘-[MainController DPbitSetReset:]’:
> MainController.m:125: warning: no ‘-id’ method found
> MainController.m:125: warning: (Messages without a matching method signature
> MainController.m:125: warning: will be assumed to return ‘id’ and accept
> MainController.m:125: warning: ‘...’ as arguments.)
> MainController.m:171: error: ‘DPbitReset’ undeclared (first use in this 
> function)
> MainController.m:171: error: (Each undeclared identifier is reported only once
> MainController.m:171: error: for each function it appears in.)
> make[3]: *** [obj/LPT_Interface.obj/MainController.m.o] Error 1
> make[2]: *** [internal-app-run-compile-submake] Error 2
> make[1]: *** [LPT_Interface.all.app.variables] Error 2
> make: *** [internal-all] Error 2
> 
> So one can't to use button 'id' attribute to determine which one sent
> the action message? 
> 
> Any advices will be appreciated!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]