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 » Community » Newbie corner » Friends? Cousins? Half-siblings?
Friends? Cousins? Half-siblings? [message #54977] Sat, 03 October 2020 01:57 Go to next message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
Having a great time working with U++, and learning a lot as I go Smile One issue I have, a main window class has several subwindow classes as members thus:
class MainWindow : TopWindow {
    SecondWin second;
    ThirdWin  third;
public:
    MainWindow();
}

class SecondWin : TopWindow {
public:
    SecondWin();
    SecondUpdate();
}

class ThirdWin : TopWindow {
public:
    ThirdWin();
    DoSomething();
}

and
...
MainWindow().Run();



Now my question, and yes I'm a newb LOL, is how do I call SecondUpdate() from within DoSomething()?

Thank you Smile

Jim

[Updated on: Sat, 03 October 2020 01:58]

Report message to a moderator

Re: Friends? Cousins? Half-siblings? [message #54980 is a reply to message #54977] Sat, 03 October 2020 08:31 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3404
Registered: August 2008
Senior Veteran
In my case I either pass a pointer to the parent window, a pointer to the window you want to call, or a callback to a lambda that opens the window. Lately I prefer the last option.

Best regards
IƱaki
Re: Friends? Cousins? Half-siblings? [message #54984 is a reply to message #54977] Sat, 03 October 2020 19:09 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
Thank you, Koldo, for that. I'm not sure how I'd implement any of those with
the TopWindow classes as I don't have much experience with all of this.

I'm using one window class to modify linked tables in my db. I have other window
classes that can view and manipulate those tables individually.

If I create a new record, it will affect at least 2 tables. I want the views of
each of the affected tables to requery each time they are accessed. Currently, if
I create a new record, and then go to view one of the affected tables, it does not
show the new record. I have to exit the program, then rerun to see it.

I haven't found a function that relates to the Open() command that causes it to
re validate it's data... so when I lineitemview.Open(this) it should requery each
time, which is why I was looking for a way for the one class to access functions
from the other classes (ie. ReQuery).
Re: Friends? Cousins? Half-siblings? [message #54987 is a reply to message #54984] Sat, 03 October 2020 20:56 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Jimlef,

Without thinking about Upp, you could implement in second and third window a reference to the master window (the first one opened), then with this references, you can access to all function of your 3 windows :

class MainWindow : TopWindow {
private:
    SecondWin second;
    ThirdWin  third;
public:
    MainWindow() : second(*this), third(*this){}
    
    SecondWin& GetSecond(){return second;}
    ThirdWin& GetThird(){return third;}
}

class SecondWin : TopWindow {
private:
	MainWindow& mainWindow;
public:
    SecondWin(MainWindow& _mainWindow) : mainWindow(_mainWindow) { /*Your code here, can be in .cpp too */ }
    SecondUpdate();
}

class ThirdWin : TopWindow {
private:
	MainWindow& mainWindow;
public:
    ThirdWin(MainWindow& _mainWindow) : mainWindow(_mainWindow) { /*Your code here, can be in .cpp too */ }
    DoSomething(){
		//Here I call the SecondUpdate() function from SecondWin:
		mainWindow.GetSecond().SecondUpdate();
    }
}


Hope it helped ! Very Happy
Re: Friends? Cousins? Half-siblings? [message #54991 is a reply to message #54977] Sun, 04 October 2020 04:48 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
Xemuth, thank you for the code samples - I didn't realize that could be done that way (I'm new to ++ after all).
Re: Friends? Cousins? Half-siblings? [message #54992 is a reply to message #54977] Sun, 04 October 2020 07:06 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
I believe I overthink things too much - someone (several someones actually) told me that before...

My solution to this issue is to override the Open function for each affected table/class thus:
void InvoicesWindow::Open(Ctrl* owner)
{
	InvoicesArray.ReQuery();
	InvoicesArray.GoBegin();
	
	TopWindow::Open(owner);
}


That way I don't need to expose extra access, pass pointers etc...

I haven't found any issues with this yet... Rolling Eyes Thanks all!
Re: Friends? Cousins? Half-siblings? [message #54995 is a reply to message #54992] Sun, 04 October 2020 09:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14164
Registered: November 2005
Ultimate Member
jimlef wrote on Sun, 04 October 2020 07:06
I believe I overthink things too much - someone (several someones actually) told me that before...

My solution to this issue is to override the Open function for each affected table/class thus:
void InvoicesWindow::Open(Ctrl* owner)
{
	InvoicesArray.ReQuery();
	InvoicesArray.GoBegin();
	
	TopWindow::Open(owner);
}


That way I don't need to expose extra access, pass pointers etc...

I haven't found any issues with this yet... Rolling Eyes Thanks all!


Uh, not sure that is the best approach either, but it certailny works.

The reason why it is not the best approach is that generally we want widgets "decoupled" from the gui.

Why don't you just call that ReQuery before you open the window? Smile

Mirek
Re: Friends? Cousins? Half-siblings? [message #55003 is a reply to message #54977] Sun, 04 October 2020 15:42 Go to previous message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
Nod Yes, I like that better - Thank you Mirek Grin
Previous Topic: double click
Next Topic: sqlarray and sqlite
Goto Forum:
  


Current Time: Sat Dec 14 15:04:34 CET 2024

Total time taken to generate the page: 0.03092 seconds