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 » Passing an ArrayCtrl / SqlArray to a function template
Passing an ArrayCtrl / SqlArray to a function template [message #49276] Mon, 15 January 2018 11:51 Go to next message
Giorgio is currently offline  Giorgio
Messages: 170
Registered: August 2015
Experienced Member
Hi folks,
I am creating a small util library for my applications (actually, is a namespace).

I use frequently a method to export the content of a SqlArray /ArrayCtrl to a csv file, so it makes sense to include it in this library.

template <class T>
	void ExportCSV(T o)
	{
		String filename = "";
		FileSel fs;
	
		CoInitialize(NULL);
		PWSTR path = 0;
		SHGetKnownFolderPath(FOLDERID_Desktop, KF_FLAG_SIMPLE_IDLIST, NULL, &path);
		std::wstring s = path;
		std::string homedir( s.begin(), s.end() );
		homedir.append("\\");
		CoTaskMemFree(path);
		
		fs.Type("CSV", "*.csv");
		fs.PreSelect(homedir);
		if(!fs.ExecuteSaveAs()) return;
		filename = fs;
		SaveFile(filename, "Prova");
		FileOut out(filename);
		if(!out) {
			Exclamation(t_("Failed opening ") + filename);
			return;
		}
		
		out.Put(o.AsCsv());
	}


When I compile I get the following error:

error C2280: 'Upp::ArrayCtrl::ArrayCtrl(Upp::ArrayCtrl &)': attempting to reference a deleted function

I know this is a really generic question, but I am bit lost.

Regards,
Gio
Re: Passing an ArrayCtrl / SqlArray to a function template [message #49281 is a reply to message #49276] Mon, 15 January 2018 14:13 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 182
Registered: March 2010
Experienced Member
Hi,

a Ctrl can't passed by value, use reference instead:
	void ExportCSV(T& o)


PS: think about using GetDesktopFolder ()
template <class T>
	void ExportCSV(T& o)
	{
		String filename = "";
		FileSel fs;
	
		fs.Type("CSV", "*.csv");
		fs.PreSelect(GetDesktopFolder ());
		if(!fs.ExecuteSaveAs()) return;
		filename = fs;
		SaveFile(filename, "Prova");
		FileOut out(filename);
		if(!out) {
			Exclamation(t_("Failed opening ") + filename);
			return;
		}
		
		out.Put(o.AsCsv());
	}


regards
omari.
Re: Passing an ArrayCtrl / SqlArray to a function template [message #49283 is a reply to message #49281] Mon, 15 January 2018 16:48 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 170
Registered: August 2015
Experienced Member
Hi Omari,
thank you for your prompt answer.

Do you know if it is possible to use a function of a namespace with THISBACK?

My utilities library is defined as a namespace named util.
When I use the following syntax:

buttonExport.WhenPush = THISBACK1(util::ExportCSV, Jobs);


I got from the compiler Error C3083, Error C2039, Error C2065.

So I had to define a method:

void JobList::Do_export()
{
	util::ExportCSV(Jobs);
}


And then assign that method to the button:

buttonExport.WhenPush = THISBACK(Do_export);


Regards,
Giorgio
Re: Passing an ArrayCtrl / SqlArray to a function template [message #49284 is a reply to message #49283] Mon, 15 January 2018 17:39 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 182
Registered: March 2010
Experienced Member
for your case, I think the best is to use lambda expression :
buttonExport << [&] {util::ExportCSV(Jobs);};


to answer your question, THISBACK only accepts memeber functions.
for a global function, uses callback:
buttonExport.WhenPush = callback1(util::ExportCSV, Jobs);


regards
omari.

[Updated on: Mon, 15 January 2018 17:39]

Report message to a moderator

Re: Passing an ArrayCtrl / SqlArray to a function template [message #49289 is a reply to message #49284] Tue, 16 January 2018 09:46 Go to previous message
Giorgio is currently offline  Giorgio
Messages: 170
Registered: August 2015
Experienced Member
Many thanks!
Previous Topic: build methods
Next Topic: StreamRasterEncoder?
Goto Forum:
  


Current Time: Sat Feb 16 12:51:19 CET 2019

Total time taken to generate the page: 0.00642 seconds