|
Er, sorry, typing error.
m_paThingIndex should be m_atThingIndex;
so:
m_atThingIndex = new thing*[m_iArraySize];
m_atThingIndex[0] = m_atThingArray[40];
Sorry about that!
Derek.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Nothing to be sorry about I make typos all the time
Now anyone want to let me know if I was right about the double pointers being used in MFC class methods, concerning CALLBACK functions? Let me know if I'm in the right ballpark.
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
When I use the DAO SQL form:
"[MyField] = '"+strMyString+"'"
all is well unless there is a single quote in strMyString, then JET errors out with a missing parameter error.
Does anyone know a fix, or is this just another MS/MS (MicroSoft Major Screwup)?
Richard
|
|
|
|
|
Anytime you include a string in an SQL statement (either in a where clause, VALUES clause, SET clause, etc). Single quotes must be dealt with before including the string in SQL. You do this by double-single quoting them.
ie. ("I can't swim") becomes ("I can''t swim").
When you insert this into the database, the DB server will only store one of the single quotes.
|
|
|
|
|
Hi,
I have question of you,
Why you wrote your field name between [ and ] ?
When i must use [ and ] ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
In SQL, you must enclose any field names that contain spaces in the brackets. SQL doesn't know that 'User Name', for example, is a field name; it sees it as two words.
Select User Name, Password From Users Order By User Name
This will confuse the SQL engine. It sees 'User' as a field name, and 'Name' as a keyword that it doesn't recognize. That's when you'd use the brackets:
Select [User Name], Password From Users Order By [User Name]
Now the parser know that 'User Name', and not just 'User', is the name of the field you're after. Many people get so used to using the brackets that they enclose ALL their fields in them out of habit. I prefer to simply leave spaces out of my field names. Where I feel space would be helpful, I'll use an underscore.
Select UserName, Password From Users Order By UserName
or
Select User_Name, Password From Users Order By User_Name
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Your answer was great ...
Now, i wanna know, what is Primary Key in Microsoft Access ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi Hadi. Primary Keys are used in pretty much every brand of database, not just Access. The Primery Key(s) of a table provide a unique way to identify its records, and is almost always an integer of some sort. If a field has been defined as a Primary Key, it may not have any records with the same data; if two records in the table had the same data in a field defined as a Primary Key, that would defeat the purpose of the Primary Key being there... identification.
Let's say you have a central company database (Access, SQL Server, Oracle, doesn't matter... they all use Primary Keys). One table is called 'Staff', and of course contains the employees of the company. The 'Staff' table has one Primary Key field called 'EmployeeID'. Another table in the database might be called 'Projects', and stores information about each project that is being worked on by the company. One of the fields in 'Projects' is also called 'EmployeeID'. If my ID is 1204, for example, this ID would be in every project that I was in charge of. Rather than put all of my information (name, age, date of hire, pay rate, etc) in to each project record, which would be redundant, we store my ID with the record. We can still get to my employee data via the ID, but I'm only storing a small number, not a complex structure of information.
Primary Keys have to be unique, meaning that no 2 records in the same table may have the same value. If another employee also had an ID of 1204, but the company charged the client differently for his/her service, than the client would be under/over billed. Not good, of course, so uniqueness is defintely a requirement.
I hope that answered your question. I know it was a somewhat involved answer, but I was hoping to be as 'unconfusing' as possible.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Hi jamie,
Thank you again for your reply, i got your mean in your reply ...
But in Design Table in microsoft access, i can use Indexed: Yes(No Duplicate) for do that ...
So, what is different between Indexed and Primary Key ???
In last, i have other question ...
I want to find all records that Name field is "Ali" or like "Ali", for example: "AliReza" or "ali1" ...
I know, i must use SQL, but where ???
SQL string: "SELECT * FROM PERSON WHERE [NAME] LIKE '%Ali%'"
But i don't know where i must use of it ???
Does i must use of CDaoRecordset::Open function ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
hi, i'd like to know if there is a way to log the strings received and sent by a certain winsock active in a program, can anyone help??? (port number is known)
Thanks
Ku
|
|
|
|
|
Hi,
i have a question on class design. I want to build a simple class to save
inifile settings in a binary fle. I started designing and made a class called
CInitfile. This class can only be used to derive classes from s then you
end up with someting like CRecStudioInitfile. Mind i'm still in the design
phase of things so the focus is on the classes, not on the code.
No i have a number of questions and i have marked the code that is related
to the question with a tag like (1) so you can see the part of the code i'm
talking about.
(1) If no arguments are passed, i want the constructur to make an init file
with the default name as specified by INIT_FILENAME. If a name is specified
i want to assign a name. Is the way i'm doing that ok in the base class?
What about the derived class?
(2) What should happen then is that in the constructor, all parameters should be initialised. Since i have 2 constructors and wanted to avoid placing the same code in both functions, i wanted to call another function from both constructors.
This initialisation is a necessity for me, so it seems like i need to specify
a pure virtual function in the base class so the derived classes woul have to build their own version. That was all going ok, but then i want to force this function to be loaded automatically by the constructor. I wanted to define this in the base class but i got an error and had to add (3) in the cpp file.
So i wanted to make sure that the baseclass initializes m_szFilename with either the default name or a name that is specified and after that, forces a function (here InitialiseParameters() ) to be called so that you are sure the memberdata is initialised. By making this function InitialiseParameters() virtual i was hoping to make sure that the derived classes should have one and by putting this in the baseconstructor i wanted to make sure the InitialiseParameters() of the derived class was called.
How do i encorporate such a design?
Thanks.
================== initfile.h ==================
#ifndef _INITFILE_H_
#define _INITFILE_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "errorexc.h"
#include "resource.h"
#define INIT_FILENAME _T("logfile.txt") // (1)
class CInitfile {
// since we don not want people to use this class immediately (they need
// to derive a class from this base class)
protected:
// constructor
CInitfile() { CInitfile(INIT_FILENAME); }; // (1)
CInitfile(const _TCHAR *szFilename) : m_szFilename(szFilename) { InitialiseParameters(); }; // (1)
// destructor
virtual ~CInitfile() {};
public:
// Pure virtual functions
virtual BOOL ReadInitfile() const = 0 ; // force derived class to make his own readfile
virtual BOOL WriteInitfile()= 0; // force derived class to make his own writefile
const _TCHAR* GetFilename() {return m_szFilename;};
private:
virtual void InitialiseParameters()=0; // this should be defined in all derived classes //(2)
const _TCHAR *m_szFilename; //filename of the file that is used to store/restore parameters too
};
class CRecStudioInitfile : public CInitfile
{
public:
// constructor & destructor
CRecStudioInitfile() {}; // (1)
CRecStudioInitfile(const _TCHAR *szFilename) : CInitfile(szFilename){}; // (1)
virtual ~CRecStudioInitfile();
BOOL ReadInitfile() const;
BOOL WriteInitfile();
// private data is all the data we want to save
private:
void InitialiseParameters(); //(2)
BOOL m_bLogMemoryToFile;
// other datamembers to come here
};
#endif // ifndef _INITFILE_H_
================== initfile.h ==================
================== initfile.cpp ==================
#include "stdafx.h"
#include "initfile.h"
// had to do this to avoid compile errors
void CInitfile::InitialiseParameters(){}; // (3)
CRecStudioInitfile::~CRecStudioInitfile()
{
}
BOOL CRecStudioInitfile::ReadInitfile() const
{
// no code yet
return TRUE;
}
BOOL CRecStudioInitfile::WriteInitfile()
{
// no code yet
return TRUE;
}
void CRecStudioInitfile::InitialiseParameters()
{
m_bLogMemoryToFile = FALSE;
// other data that needs to be initialised
}
================== initfile.cpp ==================
|
|
|
|
|
(1)
CInitfile() { CInitfile(INIT_FILENAME); }
This sucks. You're creating temporary, anonymous object of CInitFile class inside the constructor. This is not a direct call to another c'tor, this is a declaration of a variable.
(2) Virtual functions are not called virtually from constructors and destructors.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
ok, so how would one solve it/esign it then?
|
|
|
|
|
If all you have to initialize in the base class is the filename, create one c'tor with default argument:
class CInitFile
{
CInitFile(const char *szFilename = NULL);
};
CInitFile::CInitFile(const char *szFilename)
{
if (NULL == szFilename)
{
szFilename = INIT_FILENAME;
}
else
{
m_szFilename = szFilename;
}
}
You should also avoid #defining INIT_FILENAME in .h file. If you want derived classes to know this value, create static function in CInitFile.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
>>create one c'tor with default argument:
thanks. should have thought about that.
1. shouldn't i reserve memory & copy the szFilename instead of just having m_szFilename member point to it?
2. >>You should also avoid #defining INIT_FILENAME in .h file. If you want >>derived classes to know this value, create static function in CInitFile
the derived classes need to use the header file anyway, so they do know the value, don't they? What do you mean with create a static function in CInitFile.
3. How would you implement the design so i could force the derived class to make a function to initialise his member data or isn't that possible?
That's what i tried to do with the virtual void InitialiseParameters()=0;
Thanks,
bene
|
|
|
|
|
shouldn't i reserve memory & copy the szFilename instead of just having m_szFilename member point to it?
Definitely. Use CString or std::string for that.
the derived classes need to use the header file anyway, so they do know the value, don't they?
If you leave the #define in .h the will know, but this isn't a good thing. You're exposing an implementation detail and breaking encapsulation.
What do you mean with create a static function in CInitFile.
If derived classes really need to know what's the default value of filename, you should implement it this way:
class CInitFile
{
static const char* GetDefaultFilename();
};
const char* CInitFile::GetDefaultFilename()
{
return "Whatever.txt";
}
How would you implement the design so i could force the derived class to make a function to initialise his member data
You can't do that. You don't know what exactly is 'His member data'. Even if virtual function would be called virtually from ctor (it isn't), derived class could simply omit some initializations.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks Tomasz! these are the kind of answers i was looking for.
bene
|
|
|
|
|
Hi,
i have a question on class design. I want to build a simple class to save
inifile settings in a binary fle. I started designing and made a class called
CInitfile. This class can only be used to derive classes from s then you
end up with someting like CRecStudioInitfile. Mind i'm still in the design
phase of things so the focus is on the classes, not on the code.
No i have a number of questions and i have marked the code that is related
to the question with a tag like (1) so you can see the part of the code i'm
talking about.
(1) If no arguments are passed, i want the constructur to make an init file
with the default name as specified by INIT_FILENAME. If a name is specified
i want to assign a name. Is the way i'm doing that ok in the base class?
What about the derived class?
(2) What should happen then is that in the constructor, all parameters should be initialised. Since i have 2 constructors and wanted to avoid placing the same code in both functions, i wanted to call another function from both constructors.
This initialisation is a necessity for me, so it seems like i need to specify
a pure virtual function in the base class so the derived classes woul have to build their own version. That was all going ok, but then i want to force this function to be loaded automatically by the constructor. I wanted to define this in the base class but i got an error and had to add (3) in the cpp file.
So i wanted to make sure that the baseclass initializes m_szFilename with either the default name or a name that is specified and after that, forces a function (here InitialiseParameters() ) to be called so that you are sure the memberdata is initialised. By making this function InitialiseParameters() virtual i was hoping to make sure that the derived classes should have one and by putting this in the baseconstructor i wanted to make sure the InitialiseParameters() of the derived class was called.
How do i encorporate such a design?
Thanks.
================== initfile.h ==================
#ifndef _INITFILE_H_
#define _INITFILE_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "errorexc.h"
#include "resource.h"
#define INIT_FILENAME _T("logfile.txt") // (1)
class CInitfile {
// since we don not want people to use this class immediately (they need
// to derive a class from this base class)
protected:
// constructor
CInitfile() { CInitfile(INIT_FILENAME); }; // (1)
CInitfile(const _TCHAR *szFilename) : m_szFilename(szFilename) { InitialiseParameters(); }; // (1)
// destructor
virtual ~CInitfile() {};
public:
// Pure virtual functions
virtual BOOL ReadInitfile() const = 0 ; // force derived class to make his own readfile
virtual BOOL WriteInitfile()= 0; // force derived class to make his own writefile
const _TCHAR* GetFilename() {return m_szFilename;};
private:
virtual void InitialiseParameters()=0; // this should be defined in all derived classes //(2)
const _TCHAR *m_szFilename; //filename of the file that is used to store/restore parameters too
};
class CRecStudioInitfile : public CInitfile
{
public:
// constructor & destructor
CRecStudioInitfile() {}; // (1)
CRecStudioInitfile(const _TCHAR *szFilename) : CInitfile(szFilename){}; // (1)
virtual ~CRecStudioInitfile();
BOOL ReadInitfile() const;
BOOL WriteInitfile();
// private data is all the data we want to save
private:
void InitialiseParameters(); //(2)
BOOL m_bLogMemoryToFile;
// other datamembers to come here
};
#endif // ifndef _INITFILE_H_
================== initfile.h ==================
================== initfile.cpp ==================
#include "stdafx.h"
#include "initfile.h"
// had to do this to avoid compile errors
void CInitfile::InitialiseParameters(){}; // (3)
CRecStudioInitfile::~CRecStudioInitfile()
{
}
BOOL CRecStudioInitfile::ReadInitfile() const
{
// no code yet
return TRUE;
}
BOOL CRecStudioInitfile::WriteInitfile()
{
// no code yet
return TRUE;
}
void CRecStudioInitfile::InitialiseParameters()
{
m_bLogMemoryToFile = FALSE;
// other data that needs to be initialised
}
================== initfile.cpp ==================
|
|
|
|
|
pliz look at this code and tell me what is wrong here:
void CFtpExDlg::ExploreDir()
{
CFileFind finder;
BOOL b;
CString name;
//clear the list first
m_FileList.DeleteAllItems();
//clear the fImageList
int count = fImageList.GetImageCount();
for (int i = 0 ; i
|
|
|
|
|
Well the following line makes no sense ...
for (int i = 0 ; i fImageList.Remove(0);
Hope that solves your problem.
Steve T
|
|
|
|
|
Please help, I think I must be going mad!!
I'm in the middle of writing a class to do owner-drawn buttons (to combine the Cool Button of Norm Almond and the Flat Button of Davide Calabro) and I'm having a bit of trouble with the button styles.
The button I'm testing with has only the BS_OWNERDRAW style set (as enforced by the PreSubClassWindow function override). In the DrawItem override I need to check whether the BS_DEFPUSHBUTTON style is set to establish whether or not to draw a thick border. This is where the problem begins as highlighted with the following code:
BOOL bDefaultBtn = FALSE;
UINT nStyle = GetButtonStyle ();
UINT nAND = nStyle & BS_DEFPUSHBUTTON;
if (nAND == BS_DEFPUSHBUTTON) {
bDefaultBtn = TRUE;
}
BS_DEFPUSHBUTTON is defined in winuser.h (?) as 0x01L which is 0001 in binary, but BS_OWNERDRAW is defined as 0x0BL which is 1011 in binary. So, in the above example, the value for nStyle is 0x0BL (or 1011) as it should be because it's only got the BS_OWNERDRAW style set. But when I bitwise AND it with BS_DEFPUSHBUTTON (0001) I get 0001!!!!!!
The value for BS_DEFPUSHBUTTON also clashes with BS_CHECKBOX (0x02L) and BS_USERBUTTON (0x08L) although this one is now obsolete. So whenever you check an owner-drawn button for the default style it always appear to be the default when it isn't.
You can see this in evidence in either of the above two mentioned owner drawn buttons when they aren't flat because they are always drawn as default buttons, having used GetWindowLong to determine the style and AND'ed it with BS_DEFPUSHBUTTON.
Who's messed up here, me or Microsoft?? Or I am I just being stupid?
Derek.
|
|
|
|
|
Someone may problem me completely wrong
I think I've heard somewhere that you can't have a default button owner drawn, so in the owner drawn code you have to implement your own flag fo displaying a think line around it. Then to make it act as a default button, ( ) play with the tab order.
|
|
|
|
|
Thanks for your input.
It looks like thats how I'm going to have to do it
|
|
|
|
|
Hi Derek,
If you can wait a few days for this, I'm writing an article on how to solve this problem, that is how to enable default state for an owner-draw button.
I wrote 1/2 article, so please be patient.
Paolo.
|
|
|
|
|
So far I've implemented it as a separate function call in the class, which provides access to a boolean data member.
I'll be interested to read your article.
|
|
|
|
|