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 » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Please help me make this better
Please help me make this better [message #8560] Sat, 17 March 2007 19:53 Go to next message
MikeyV is currently offline  MikeyV
Messages: 20
Registered: February 2007
Promising Member
Hi,

I have a rather cumbersome block of code that I would like to streamline.
void Sats3::DoDrops() {
	// Populate the drop lists
	SQL*Select(Code).From(Generation);
	while(SQL.Fetch())
		ist.dGen.Add(SQL[0]);
	
	SQL*Select(Code).From(EdCode);
	while(SQL.Fetch())
		ist.dEdCode.Add(SQL[0]);
	
	SQL*Select(Code).From(Sex);
	while(SQL.Fetch())
		ist.dSex.Add(SQL[0]);
	
	SQL*Select(Code).From(Race);
	while(SQL.Fetch())
		ist.dRace.Add(SQL[0]);
	
	SQL*Select(Code).From(Ethnic);
	while(SQL.Fetch())
		ist.dEthnic.Add(SQL[0]);
	
	SQL*Select(Code).From(EnlType);
	while(SQL.Fetch())
		ist.dEnlType.Add(SQL[0]);
	
	SQL*Select(Code).From(Area);
	while(SQL.Fetch())
		mis.txtOpsArea.Add(SQL[0]);
}


As you can see, it just does the same thing over and over. I was thinking something like this:

void SATS3::Populate (const char *field, const char *table, const char *tab, const char *control) {
        SQL*Select(field).From(table);
        while(SQL.Fetch())
                tab.control.Add(SQL[0]);
}


And then call it like this:
Populate("Code", "Area", "ist", "dEnlType");


Any suggestions?

Mike
Re: Please help me make this better [message #8561 is a reply to message #8560] Sat, 17 March 2007 20:14 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 790
Registered: November 2005
Location: Czech Republic - Praha
Contributor

void Sats3::DoDrops() {

  static const ...FromType.. _from[] = {Generation, EdCode, Sex, Race, ..., Area};
  static const ...ControlTypePtr... _ctrl[] = {ist.dGen, ist.dEdCode, ..., mis.txtOpsArea};
//all controls must be derived from the same "..ControlType..."
//and implement virtual "Add" function with same interface

    for (int i = 0; i < sizeof(_from)/sizeof(...FromType..); ++i )
    {
	SQL*Select(Code).From(_from[i]);
	while(SQL.Fetch())
		_ctrl[i]->Add(SQL[0]);
    }

}


Something like this is possible with your current classes/types of variables?
Re: Please help me make this better [message #8562 is a reply to message #8561] Sat, 17 March 2007 20:23 Go to previous messageGo to next message
MikeyV is currently offline  MikeyV
Messages: 20
Registered: February 2007
Promising Member
Quote:

Something like this is possible with your current classes/types of variables?


Well, the const char *whatever was just me trying (badly) to pass some text.

The variables (they're not really declared variables, just some text I was trying to pass) are just text so I can replace the text. I was just trying to pass the name of a table, a column, a tabControl name, and a dropdown widget name.

So it's like:
SQL*Select(column).From(table);
	while(SQL.Fetch())
		tabcontrol.dropdownWidget.Add(SQL[0]);


But, as a newbie, I'm not sure how to go about it. I will study your approach, though.

Thanks for the answer.
Re: Please help me make this better [message #8563 is a reply to message #8560] Sat, 17 March 2007 21:08 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 576
Registered: December 2005
Location: Budapest, Hungary
Contributor
I Think, you should use const SqlId& and DropList& instead of const char *, so you could use something like:
Populate(Code, Area, istdEnlType);


void SATS3::Populate (const SqlId& field, const SqlId& table, DropList& control) {
        SQL*Select(field).From(table);
        while(SQL.Fetch())
                control.Add(SQL[0]);
}
Re: Please help me make this better [message #8564 is a reply to message #8563] Sat, 17 March 2007 21:33 Go to previous messageGo to next message
MikeyV is currently offline  MikeyV
Messages: 20
Registered: February 2007
Promising Member
I will give that a shot. Thanks!
Re: Please help me make this better [message #8565 is a reply to message #8560] Sun, 18 March 2007 07:23 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11715
Registered: November 2005
Ultimate Member
MikeyV wrote on Sat, 17 March 2007 14:53



As you can see, it just does the same thing over and over. I was thinking something like this:

void SATS3::Populate (const char *field, const char *table, const char *tab, const char *control) {
        SQL*Select(field).From(table);
        while(SQL.Fetch())
                tab.control.Add(SQL[0]);
}


And then call it like this:
Populate("Code", "Area", "ist", "dEnlType");


Any suggestions?

Mike


Yes, that is a good idea. We had it too Smile

tab.control *= Select(Code).From(Generation);


Note that often you will want to fetch pairs (key - name), then

tab.contro *= Select(Key, Code).From(Generation);


Works for DropList and MapConvert.

Mirek
Re: Please help me make this better [message #8567 is a reply to message #8565] Sun, 18 March 2007 09:35 Go to previous messageGo to next message
MikeyV is currently offline  MikeyV
Messages: 20
Registered: February 2007
Promising Member
Sweet!

Thanks Mirek

EDIT: Bah...spoke too soon.

ist is my tab, and dGen is my droplist. So I have :

ist.dGen *= Select(Code).From(Generation);

Linker returns:
C:\Development\MyApps\Sats3\Sats3.cpp(16) : error C2678: binary '*=' : no operator found which takes a left-hand operand of type 'Upp::D
	ropList' (or there is no acceptable conversion)
        C:\Development\upp\uppsrc\Core/Gtypes.h(582): could be 'Upp::Size &Upp::operator *=(Upp::Size &,double)'
        C:\Development\upp\uppsrc\Core/Gtypes.h(596): or 'Upp::Size &Upp::operator *=(Upp::Size &,Upp::Sizef)'
        C:\Development\upp\uppsrc\Core/Gtypes.h(617): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,double)'
        C:\Development\upp\uppsrc\Core/Gtypes.h(631): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,Upp::Sizef)'
        C:\Development\upp\uppsrc\RichText/RichText.h(37): or 'void Upp::operator *=(int &,Upp::Zoom)'
        C:\Development\upp\uppsrc\RichText/RichText.h(42): or 'void Upp::operator *=(Upp::Rect &,Upp::Zoom)'
        c:\development\upp\uppsrc\richtext\Para.h(282): or 'void Upp::operator *=(Upp::RichPara::Format &,Upp::Zoom)'
        c:\development\upp\uppsrc\sql\Sqlexp.h(191): or 'Upp::SqlVal &Upp::operator *=(Upp::SqlVal &,const Upp::SqlVal &)'
        while trying to match the argument list '(Upp::DropList, Upp::SqlSelect)'

[Updated on: Sun, 18 March 2007 09:48]

Report message to a moderator

Re: Please help me make this better [message #8568 is a reply to message #8567] Sun, 18 March 2007 11:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11715
Registered: November 2005
Ultimate Member
MikeyV wrote on Sun, 18 March 2007 04:35

Sweet!

Thanks Mirek

EDIT: Bah...spoke too soon.

ist is my tab, and dGen is my droplist. So I have :

ist.dGen *= Select(Code).From(Generation);

Linker returns:
C:\Development\MyApps\Sats3\Sats3.cpp(16) : error C2678: binary '*=' : no operator found which takes a left-hand operand of type 'Upp::D
	ropList' (or there is no acceptable conversion)
        C:\Development\upp\uppsrc\Core/Gtypes.h(582): could be 'Upp::Size &Upp::operator *=(Upp::Size &,double)'
        C:\Development\upp\uppsrc\Core/Gtypes.h(596): or 'Upp::Size &Upp::operator *=(Upp::Size &,Upp::Sizef)'
        C:\Development\upp\uppsrc\Core/Gtypes.h(617): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,double)'
        C:\Development\upp\uppsrc\Core/Gtypes.h(631): or 'Upp::Size16 &Upp::operator *=(Upp::Size16 &,Upp::Sizef)'
        C:\Development\upp\uppsrc\RichText/RichText.h(37): or 'void Upp::operator *=(int &,Upp::Zoom)'
        C:\Development\upp\uppsrc\RichText/RichText.h(42): or 'void Upp::operator *=(Upp::Rect &,Upp::Zoom)'
        c:\development\upp\uppsrc\richtext\Para.h(282): or 'void Upp::operator *=(Upp::RichPara::Format &,Upp::Zoom)'
        c:\development\upp\uppsrc\sql\Sqlexp.h(191): or 'Upp::SqlVal &Upp::operator *=(Upp::SqlVal &,const Upp::SqlVal &)'
        while trying to match the argument list '(Upp::DropList, Upp::SqlSelect)'



Do you have

#include <SqlCtrls/SqlCtrls.h>

?

Mirek
Re: Please help me make this better [message #8572 is a reply to message #8568] Sun, 18 March 2007 19:47 Go to previous message
MikeyV is currently offline  MikeyV
Messages: 20
Registered: February 2007
Promising Member
Quote:

Do you have

#include <SqlCtrls/SqlCtrls.h>

?



Of course not. Razz

Works great now that I included it. Thanks!
Previous Topic: Scribble examples compiling and other errors
Next Topic: Using dual-screen
Goto Forum:
  


Current Time: Sat Feb 23 20:08:45 CET 2019

Total time taken to generate the page: 0.00662 seconds