www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/03/08:57:18

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: JPTUI Question
Date: Tue, 03 Dec 1996 07:45:02 -0500
Organization: Cornell University
Lines: 134
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <32A420CE.6006@cornell.edu>
NNTP-Posting-Host: cu-dialup-0084.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

i recently downloaded jptui and i am trying to use to build the user
interface of one of my programs. i also thought it would be a good way
to finally venture into c++. (i have some knowledge of c++, mainly
through doing examples in books, but so far i have been to lazy to do
anything of my own.) anyway, the following question probably reflects my
ignorance more than anything else.

in the program, i would like to keep track of a group of "button-like"
entities and, when needed, provide a visual version. a cut down version
of my "solution" is below. Essentially, i want this class to provide a
common callback for all the buttons in the group.

When i try to compile this, with , -Wall, -02 and -m486, i get the
following message:

layout.cc: In method `void ButtonArray::SetCallbacks()':
layout.cc:63: bad argument 1 for function `void
TPushButton::m_set_pressed_callback(void (*)(class TObject *, char *),
char *)' 
(type was void (ButtonArray::)(class TObject *, char *))

i understand that the compiler does not see Pressed as an appropriate
function pointer, but i am lost as to why not.

any help will be most appreciated.

sinan.

/*
 * Layout.CC
 */

#include <jptui.h>
#include <stdio.h>
#include <string.h>

TApplication	Layout(NONE);

TWindow			Main(DIALOG1, 1, 1, 65, 20, "Layout Test", INFO_BAR,
NOT_MODAL);

struct ButtonInfo
{	TPushButton *Button;
	int m_clicked_count;
};

struct ButAttr
{	int rel_x;
	int rel_y;
	int width;
	char caption[16];
};

class	ButtonArray
{	private :
		struct ButtonInfo *Info;
		int m_no_of_buttons;
	public :

   	ButtonArray(PWindow parent, int no_of_buttons, struct
ButAttr           *PButAttr)
        {
			m_no_of_buttons = no_of_buttons;
        	Info = new struct ButtonInfo[m_no_of_buttons];
        	for ( int i = m_no_of_buttons; i; i--)
        	{
	         	(Info+i)->m_clicked_count = 0;
         		(Info+i)->Button = new TPushButton(parent,
       							PButAttr->rel_x,                     PButAttr->rel_y,
PButAttr->width, PButAttr->caption);
				PButAttr++;
        	}
	}
	void Pressed(PObject sender, char *)
		{
		    char caption[16];
		    struct ButtonInfo *p = Info;
			for (int i = m_no_of_buttons; i; i--)
		    {
				if ( p->Button == sender )
					break;
		        p++;
		    }
			sprintf(caption, "%i", ++(p->m_clicked_count));
			(p->Button)->m_set_caption(caption);
		}

    void SetCallbacks(void)
    {
        	for ( int i = m_no_of_buttons; i; i--)
                ((Info+i)->Button)->m_set_pressed_callback(Pressed, "");
	}

   ~ButtonArray(void)
        {
        	for (int i = m_no_of_buttons; i; i--)
        		delete ((Info+i)->Button);
        	delete [] Info;
         }
};

void Quit(PObject, char*)
{
 	JPStop();
}

int main(int argc, char *argv[])
{
    JPInit();
	struct ButAttr BAttr[24];
	for( int i = 0; i < 3 ; i++)
    	for( int j = 0; j < 8 ; j++)
        {
        int t = i*8+j;
		BAttr[t].rel_x = 2 + j*7; BAttr[t].rel_y = 5 + i*3;
		BAttr[t].width = 6;
		strcpy(BAttr[t].caption, "0");
        }
	ButtonArray BArr(&Main, 24, BAttr);
    BArr::SetCallbacks();

    Main.m_set_close_button_pressed_callback(Quit, "");
    Main.m_open();
    JPRun();
    return 0;
}
-- 
*******************************************************************
 A. Sinan Unur                                WWWWWW
                                              |--O+O
 mailto:asu1 AT cornell DOT edu                      C   ^ 
 mailto:sinan AT econ DOT cit DOT cornell DOT edu             \  ~/ 
 http://www.bqnet.com/sinan/
*******************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019