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: Csanyi Pal
Subject: Re: Determining which button was clicked using it's id attribute
Date: Fri, 19 Nov 2010 20:40:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hello Jason,

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!

-- 
Regards, Paul Chany
<http://sourceforge.net/projects/lptinterface/>
<http://savannah.nongnu.org/projects/lpt-interface/>
<http://csanyi-pal.info>




reply via email to

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