Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How to call instance in main.cpp
How to call instance in main.cpp [message #5127] Wed, 06 September 2006 16:32 Go to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
I have sereral files.LeftCtrl.h,RightCtrl.h,main.cpp,and I create a
database instance in structure App(in main.cpp),quetion is in LeftCtrl.h how to call this database instance?in MFC,there is a routine:AfxGetApp() to get the point of App,in U++,how to do this ?
Re: How to call instance in main.cpp [message #5128 is a reply to message #5127] Wed, 06 September 2006 16:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Database instance? Like Oracle or MySQL? But that has nothing to do with AfxGetApp...

I guess what you want is to get some reference to the main window?

There is nothing like AfxGetApp in U++. All top-level owner-less windows are peer. You can get a list of all top-level windows or Ctrls by calling

static Vector<Ctrl *> Ctrl::GetTopCtrls();
static Vector<Ctrl *> Ctrl::GetTopWindows();

if this does not help, what did you plan to do with AfxGetApp-like function?

Mirek
Re: How to call instance in main.cpp [message #5129 is a reply to message #5128] Wed, 06 September 2006 17:17 Go to previous messageGo to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
well,that's hard to describe,let's see some code:

in main.cpp:
struct App : public TopWindow
{
ULeftCtrl Left;
URightCtrl Right;
....
CppSQLite3DB database;//that is another
String exeDML(const char* szSQL);
//this routine to parse szSQL and record every INSERT or UPDATE with acture ROWID.
....
}
GUI_APP_MAIN
{
App().Run();
}

in LeftCtrl.h(represent Left Pane) somewhere
want to call database.xxx and exeDML()

==================================================
static Vector<Ctrl *> Ctrl::GetTopCtrls();
static Vector<Ctrl *> Ctrl::GetTopWindows();

is that get App struct?

if not this not help,I can define database pointer in LeftCtrl.h and then in App::App() make this pointer point to database,but I got no idea with exeDML.I have to consider trigger or some other way.

[Updated on: Wed, 06 September 2006 17:27]

Report message to a moderator

Re: How to call instance in main.cpp [message #5131 is a reply to message #5129] Wed, 06 September 2006 17:45 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Ulti wrote on Wed, 06 September 2006 11:17

well,that's hard to describe,let's see some code:

in main.cpp:
struct App : public TopWindow
{
ULeftCtrl Left;
URightCtrl Right;
....
CppSQLite3DB database;//that is another
String exeDML(const char* szSQL);
//this routine to parse szSQL and record every INSERT or UPDATE with acture ROWID.
....
}
GUI_APP_MAIN
{
App().Run();
}

in LeftCtrl.h(represent Left Pane) somewhere
want to call database.xxx and exeDML()

==================================================
static Vector<Ctrl *> Ctrl::GetTopCtrls();
static Vector<Ctrl *> Ctrl::GetTopWindows();

is that get App struct?

if not this not help,I can define database pointer in LeftCtrl.h and then in App::App() make this pointer point to database,but I got no idea with exeDML.I have to consider trigger or some other way.


What about to simply make things global? In the end AfxGetApp is an global variable (accessed via function) too.

Mirek
Re: How to call instance in main.cpp [message #5132 is a reply to message #5131] Wed, 06 September 2006 17:54 Go to previous messageGo to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
luzr wrote on Wed, 06 September 2006 11:45



What about to simply make things global? In the end AfxGetApp is an global variable (accessed via function) too.

Mirek


That can help,I will give it a try,but looks not so C++. Razz

[Updated on: Wed, 06 September 2006 17:55]

Report message to a moderator

Re: How to call instance in main.cpp [message #5133 is a reply to message #5132] Wed, 06 September 2006 18:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, sure, but you cannot take that literally. "Not use globals" recommendation is for beginner coders that tend to overuse them.

Also not that AfxGetApp is no better, it is simply a global in disguise. If you really need / want to make things independent of global issues, you have to propagate your database as reference in dependant sub-ctrls.

Mirek
Re: How to call instance in main.cpp [message #5139 is a reply to message #5133] Thu, 07 September 2006 01:57 Go to previous messageGo to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
I got another idea,I will put the database in a logical lowest level class,so every other file include this file.and can easy call the database instance,I tried it,it worked.thanks
Re: How to call instance in main.cpp [message #5143 is a reply to message #5139] Thu, 07 September 2006 12:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I do not quite understand what you mean... (but if it works..)

Mirek
Re: How to call instance in main.cpp [message #5144 is a reply to message #5143] Thu, 07 September 2006 15:23 Go to previous message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
OK,here is the code structure:
Three files: main.cpp,LeftCtrl.h,RightCtrl.h
======================================================
main.cpp
#include "LeftCtrl.h"
struct App : public TopWindow
{.....
ULeftCtrl Left;
URightCtrl Right;
.....};

App::App()
{
h.Horz(Left,Right); Left.right=&Right;
.....}
======================================================
LeftCtrl.h
#include "RightCtrl.h"
class ULeftCtrl : public WithULeftCtrl<TopWindow> {
.....;URightCtrl * right;};
======================================================
RightCtrl.h
#include "CppSQLite/CppSQLite3.h" //<==move here now
class URightCtrl : public WithURightCtrl<TopWindow> {
....
CppSQLite3DB database;
String exeDML(const char* szSQL);
....;};
======================================================

in App call Ringht.database,Right.excDML
in LeftCtrl call right->database,right->exeDML
maybe & is more better.
Smile

Previous Topic: always-on-top window
Next Topic: StaticRect blocks mouse events - deliberate?
Goto Forum:
  


Current Time: Fri Apr 19 20:09:09 CEST 2024

Total time taken to generate the page: 0.04349 seconds