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 » FileSel&FileList, Path » FileSelector lambda troubles
FileSelector lambda troubles [message #47813] Sun, 02 April 2017 13:38 Go to next message
germax is currently offline  germax
Messages: 20
Registered: March 2017
Location: germany
Promising Member
And another brick wall I need to chew myself through Sad

I have a FileDialog (defined in .lay) that I now want to add a 'convenience' button to
that opens the FileSelector and then copies the path over to my input box.

Again, for a more experienced man than I am, that shouldn't be much of an issue, right?

I'm still stuck somehow.. here are some lines of nastyness
....	
NewFLdlg dlg;
/* 
dlg is my file dialog and apart from some bits and bolts 
it has a button ofs (open file selector)
and an editstring path (to take ... you guessed it ... my file path)
*/ 
String fsp = "nixx"; // just a String I added to test if the lambda can read 'outside'
dlg.button.WhenPush = [=]
{
	FileSelector fs; 
	fs.AllFilesType().Multi(true);
	if(fs.ExecuteOpen("Dummy Demo"))
		PromptOK("\1"+~fs);
	else
		PrompOK(fsp); // works so far...
/* BUT

		fsp = ~fs; // is not working since fsp is now a const 
		//error: passing 'const Upp::String' as 'this' argument discards qualifiers [-fpermissive]
		PromptOK(AsString(~dlg.path)); // error: use of deleted function 'NewFLdlg::NewFLdlg(NewFLdlg&)'
Not even mentioning
		dlg.path = ~fs; // what I'm really after 

*/
};
.....


I'd like to avoid to add a callback (well a non lambda callback that is Wink)
if at all possible.

Any hints?

Thanks alot

Alex


that other german guy
Re: FileSelector lambda troubles [message #47816 is a reply to message #47813] Sun, 02 April 2017 20:48 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Try
dlg.button.WhenPush = [&]

Instead of
dlg.button.WhenPush = [=]


regards
omari.
Re: FileSelector lambda troubles [message #47818 is a reply to message #47813] Sun, 02 April 2017 23:25 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

For me the overall design of this dialogue is strange and wearied. What you want to do is to have dialog class that returns some specific value:
class NewFLdlg final : public WithMyAweasomeLayout<TopWindow>
{
public:
    NewFLdlg() {
        // This callback logic should be implemented here... (Not outside the class - I am not surre why we have public inheritance here)
        button.WhenAction = [=] {
            // this->fsp should be available here.
        }
    }    

    String GetFsp() const { return fsp; }

private:
    String fsp;
};

// Then in the main code
NewFLdlg dlg;
if (dlg.Execute() == IDOK) // Check if user close dialog with success - you need "OK" button for such operations...
{
    String fsp = dlg.GetFsp(); // Here you should have valid fsp with nice object related design.
}



Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Sun, 02 April 2017 23:25]

Report message to a moderator

Re: FileSelector lambda troubles [message #47820 is a reply to message #47818] Mon, 03 April 2017 01:23 Go to previous message
germax is currently offline  germax
Messages: 20
Registered: March 2017
Location: germany
Promising Member
Klugier.. what?
nonoono..

it's inside my class inside a void function of my class of course..
it's just not interesting what this function does really
(nothing but copying the path to a database really along with some other data set by the dialog)
I just wanted to keep the code window as small as possible to not clutter it up with the obvious stuff Wink

omari.. THANKS A MILLION!!
that works like a charm Very Happy
thank you, thank you, thank you... saved me another day of searching the internet for a solution Very Happy

Cheers
Alex


that other german guy
Previous Topic: Common Dialog
Next Topic: Different GetHomeDirectory() in PLATFORM_POSIX and PLATFORM_WIN32
Goto Forum:
  


Current Time: Fri Mar 29 15:13:23 CET 2024

Total time taken to generate the page: 0.01601 seconds