|
Ummm, you got the method name case wrong...
CString sBuffer(_T("The coffee smells terrible"));
if (sBuffer.Find("err") >= 0)
{
}
else
{
}
Also, keep in mind that string searches in a CString are case-sensitive, so if that matters, you may want to use the CString::MakeLower() function befoire running your search.
|
|
|
|
|
Hi,
How to totally remove the help button from a wizard
(CPropertySheetEx)? thanks.
p.c.
|
|
|
|
|
One Way:
BOOL CMyPropertySheet::OnInitDialog()
{
CPropertySheetEx::OnInitDialog();
// this hides the Help button
CWnd* pHelpButton = GetDlgItem (IDHELP);
ASSERT (pHelpButton);
if (pHelpButton)
pHelpButton->ShowWindow (SW_HIDE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Bill
|
|
|
|
|
Search MSDN for PSP_HASHELP and PSH_HASHELP
You have to remove those flags from pages/sheet to completely remove help button. You may do this in the constructor.
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
I'm pretty new to ADO and need some guidence. I'm using MS Access 2K. I have
three tables. The tables looks as follows:
UserAccounts
------------
UserAcctID (key, autonumber)
UserAcctData
Queues
------
QueueID (key, autonumber)
QueueName
QueueRights
-----------
UserAcctID (foreign key)
QueueID (foreign key)
Rights
I'm using ADO and DCOM so there's potential of multiple admin users trying
to access and modify the tables at one time. I need to ensure that referential
integrity is ensured, and wondered if developers typically use locking mechanisms
or the referential integrity tool in MS Access, or both.
I also, have the following situations, and am not sure of the best way to resolve
them in terms of locking and ensuring that the keys/data won't be out of sync:
1) When one admin is editing another user's account, another admin cannot edit that
user's account. What's the best way to lock the account? Add a lock timestamp
column to UserAccounts?
Also, is this a user-friendly restriction? Do other administration program lock
another user from editing the same account, or do they allow them to edit it and
then notify them that it has changed when it's time to update and for them to reload
and redo what they've done?
2) When an admin is about to update another user's queue rights, I would need to
lock the entire "Queues" table from being added to while records are being added
or updated to the QueueRights table. What's the best way of accomplishing that?
3) Also are there any good websites and/or books that discusses how to resolve
issues with multiple users and databases?
Thanks in advance for any help!
|
|
|
|
|
Hi,
I want to use a CTabCtrl, not a propery sheet.
What I am looking for is a convenient way to design each of the tab pages, and hide & show them.
What's the common way of using a CTabCtrl to embed pages. Quite shocked by the lack of resources on this topic, or is it actually straight forward?
Cheers Again!
Richard
|
|
|
|
|
Hi
I'm new to c++ and like to know what's the difference between these two declarations:
int something[20];
and
int *something = new int[20]
delete something;
|
|
|
|
|
10 ints.
in the first sample, the 30 ints are allocated on the stack and are therefore cleaned-up automatically when the program leaves the function - so they don't live outside that function. in the second, they are allocated on the heap and you have to clean them up yourself.
one benefit of the first is automatic clean up. one benefit of the second is that the data can have a lifetime longer than that of the function that allocated it.
just a note: in general, it's not nice to allocate large amounts of memory on the stack (30 ints isn't "large").
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thanks, now I want to check if I unterstand what you just explain
void func1()
{
int something[20];
...
}
void func2()
{
int *something = new int[20];
...
delete something;
}
In func1 the variable isn't available anymore after the function has quit, in func2 it is available even after the function has quit?
|
|
|
|
|
No, because you
a/ did not store the pointer, and
b/ deleted it.
What *is* true is if I had a vector ( an array class in the Standard Template Library ) that stored pointers to ints ( normally it would make no sense to store an int pointer, you may well, however, store a pointer to a struct or class you defined, or something like a bitmap ), then if I did this:
int i = 20;
myvector.push_back(&i);
I would be in trouble, as I would have stored the address of an int that went out of scope and was destroyed. This is one of the two dangers of pointers - if I store a memory address and the contents get deleted, if I try to use it, everything is likely to die in a hurry.
If I did this though:
int * pInt = new int;
pInt = 20;
myvector.push_back(pInt);
then I am fine - the int won't be destroyed as using a pointer put me in control of that, and memory is not leaked ( the other danger, forgetting to delete something or remember the pointer value ( the address in memory it is stored ) ) because my vector takes responsbility for storing the pointer.
The reason one might do this with large objects is because it is super fast to pass a pointer into a function, for example, because you're moving a memory location, not a huge chunk of data.
Hope that helps.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
First off, in the second function you should be using operator delete[], or else your just deleting the first allocated integer -- and thus a memory leak.
void func2() {
int * something = new int[20];
delete [] something;
}
>>>
In func1 the variable isn't available anymore after the function has quit, in func2 it is available even after the function has quit?
<<<
Almost, since you delete the array in func2 it will no longer exist. But had you not called delete the memory would have persisted even after the function went out of scope.
Doing something like this;
int * func2() {
int * something = new int[20];
return something;
}
Would preserve the allocated memory, even after the function goes out of scope.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
First off, in the second function you should be using operator delete[], or else your just deleting the first allocated integer -- and thus a memory leak.
Ooops - I missed that one. As a matter of interest, while I would never advocate using anything other than delete [] for an array, I am led to believe under VC++ it makes no difference because of the way it is implimented.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
>>>
Ooops - I missed that one. As a matter of interest, while I would never advocate using anything other than delete [] for an array, I am led to believe under VC++ it makes no difference because of the way it is implimented.
<<<
Good call, unless my debugger is missing the leak, it seems to work perfectly... very strange.
>>>
The careful application of terror is also a form of communication.
<<<
Did you by any chance have a talk with my professors? He seems to have adopted the same philosophy
cheers,
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hello, the codegurus around the world.;)
We can keep the variable by the global variable, reference, and pointer
to keep the variable alive out of the function in especially C.
1) Delcare int something[20] as the global variable.
2) Use the reference by the function parameter.
void func1(int &a[20]);
3) Use the pointer by the funtion parameter
void func2(int *a);
In C++, we can use the member variable by private or protect,
we can simply assign this array or pointer to the new value
inside the function.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
>First off, in the second function you should be
>using operator delete[], or else your just deleting
>the first allocated integer -- and thus a memory
>leak.
This is innacurate. The operator 'delete[]' calls a destructor for each member of an array while the operator 'delete' simply deletes the array itself. For simple types which require no destructor, 'delete' works just fine.
(Note: This is definitely Visual C++ behavior. Some may argue that this isn't strictly ANSI C++ but I disagree and here's why: delete[] indicates that I am deleting an array of objects, delete indicates that I am deleting an object which may, or may not, be an array.
Having said that, I actually use malloc/free for the latter case. It's usually faster and makes for clearer code since it indicates that what I wanted was a chunk of memory, nothing more, nothing less.)
|
|
|
|
|
Hi,
i'm programming a demo in win32 and i'm putting everything in classes. Now since i don't use MFC, i need a c++ (not willing to use STL) class that implements an array of objects or a list of objects. This list/array would need to have a quick search algoritm and ideally sorting.
Does anybody know where i can find such a class? Basically all my objects will be in memory after i have read them from file and that will be about 5000-10000 records (objects) maximum. I'm not sure what would be better, a array or a list.
Thanks.
|
|
|
|
|
Ideally you should probably use a binary tree - it will sort in place and be quick to search. Map is one implimentation, but for some reason you don't want to use the tools C++ provides ( STL ) and instead want to write your own. If this is for a learning exercise then great, if not, then what's the problem with STL ?
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
the reason i don't want (i don't dislike it) to use STL is that i don't think the code is that clear. Plus i don't like their nameing conventions they use. When you write your own classes, you have access to the code as well.
|
|
|
|
|
A simple list is inherently slow to search, because you can only go through sequentially. Your best bet is probably a binary tree (though it depends how your data is organised before loading. Simple binary trees are a disaster if your data is allready sorted).
If your data is loaded in order, use a straight array and search with a binary chop.
If your data is loaded at random use a binary tree. Building a binary tree is pretty trivial if you don't care about balancing (required for optimal search times).
<br />
class CMyNode {<br />
char *key;
...<br />
...<br />
CMyNode *children[2];
<br />
static CMyNode *root;<br />
<br />
CMyNode(...)<br />
static CMyNode *find(const char *);<br />
};<br />
<br />
CMyNode::CMyNode( ... ) {<br />
<br />
...<br />
<br />
CMyNode *p,**pp = &root;<br />
while((p = *pp) != NULL) {<br />
int cmp = strcmp(key, p->key);<br />
if(cmp == 0) {<br />
.. duplicate (Error? )<br />
} else<br />
pp = &p->children[cmp < 0 ? 0 : 1];<br />
}<br />
*pp = this;<br />
children[0] = NULL;<br />
children[1] = NULL;<br />
<br />
..<br />
}<br />
<br />
CMyNode CMyNode::find(const char *key) {<br />
CMyNode *p;<br />
int cmp;<br />
<br />
for(p = root; p; p = p->children[cmp < 0]) {<br />
cmp = strcmp(key, p->key);<br />
if(!cmp)<br />
return p;<br />
}<br />
return NULL;<br />
}<br />
|
|
|
|
|
Thanks for the code.
If i understand correctly, if i'm going to use your code, every node needs a keyvalue and i best not write them to disk sorted. Am i correct?
What if you would have a class with an id, name, and say integer and you want to be able to search for the id, the name and the integer value, would that mean that you have to construct the binary tree every time again for the data? Or would you have 3 binary trees for that 1 class?
Wouldn't a linked list with a simple sort ( quicksort ) be faster then or at least easier to use? Although (i could be wrong) i ahve heard that a binary search is faster.
|
|
|
|
|
The code was a generic example which assumed the key was a text string. If you use another kind of key you need to replace the strcmp with a suitable equivalent comparator (if your records are searchable you obviously do have keys).
If you want several alternate keys you can use the same actual set of nodes to create several trees, each tree has it's own children and root pointers in each node. You only need one set of nodes, but you have several arrangements going at the same time. (Assuming that you search separately for the different keys. If you want to search on a combined key, just combine the comparator).
The trouble with a simple linked list is that you can only walk through it sequentially. You can't, for example, go straight to the middle element for a binary chop.
The binary tree is a binary search, with the same order of search time as a binary chop into a sorted table (order of log(n)).
The only thing is that the tree works efficiently only if it's approximately balanced. That's why it screws up if you put the keys in in sorted order. You wind up adding everything on one branch and it degenerates to a simple list (it still works, but you lose the speed advantage). If the data are random then, on average, the tree will be reasonably balanced. There are algorithms for rebalancing a tree but, believe me, you don't want to know.
|
|
|
|
|
OK, thanks for the info. It cleared up some of the questions i had. You wouldn't have some links to site which have more explanation on this?
|
|
|
|
|
Salut!
Dans un environement Client\Serveur Comment utiliser les threads afin que le Serveur puisse gerer tout les clients du réseau? Est que il faut passer imperativement par les threads d'interface? A partir de quelle fonction on doit lancer le thread (accept?).
Priere de détailler vos réponces afin qu'on puisse comprendre.
Salutations distinguées.
|
|
|
|
|
hmm, in english would be better. this is an international forum
|
|
|
|
|
hee hee..
Nous ne parlons pas Français bien. (or was it meilleur?..)
Voulez-vous parler en Anglais s'il vous plait?
Merci beaucoup!
Baaf.
_________
So, what do you think of my French?
|
|
|
|
|