|
DavidCrow wrote: "thunking"
Whoa - there's a word I haven't heard or used in a long long time
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
Hi
<br />
CList<class Customer> ListCustomers;<br />
<br />
Customer * pJohn = new Customer("John");<br />
Customer * pMary = new Customer("Mary");<br />
ListCustomers.AddTail(pJohn);<br />
ListCustomers.AddTail(pMary);<br />
Question is, should I manually delete allocated memory?
Thanks
devy
|
|
|
|
|
Yes, when you remove the element for the list, you should delete the memory. But you should do that only when the element is removed from the list.
|
|
|
|
|
Thanks... so I should do this?
<br />
CList ListCustomers;<br />
<br />
Customer * pJohn = new Customer("John");<br />
Customer * pMary = new Customer("Mary");<br />
ListCustomers.AddTail(pJohn);<br />
ListCustomers.AddTail(pMary);<br />
<br />
delete pJohn;<br />
pJohn = NULL;<br />
delete pMary;<br />
pMary = NULL;<br />
ListCustomers.RemoveAll();<br />
devy
|
|
|
|
|
In general, you add elements to the list and you don't keep the pointers to each individual elements (otherwise, why would you use a list ??). So, when you want to empty the list, you don't have those pointers directly but they are stored in the map. What you have to do is just iterate through your list and delete each item in the list and then call RemoveAll.
In other situations, it can also happen that you want to remove only one element from your list. Then, you simply delete this element and remove it from the list.
Hope that helps
|
|
|
|
|
I have a Resource file from where Dialog takes the static content that i want to display.
say LTEXT "Select",IDC_STATIC,....
where "Select" would gets displayed on to the dialog box on pop up
But I don't wanna do this way ...
Wat i want is smthng like
LTEXT str_Data,IDC_STATIC,...
where
str_Data is of type CString and gets its value from a function
say...
str_Data = getData("Select");
and Function is CString getData(LPCTSTR);
or sumthng like #define str_Data
and LTEXT str_Data,IDC_STATIC,...
and the rest remains same as above
Do , anyone has any idea...
|
|
|
|
|
I dont understand what do you need?you have a file and you want to display content of this file with a static control,right?
|
|
|
|
|
In VC++, you have a Resource file which has all the information regarding what ur dialog will contain , sumthng like this
LTEXT "Click View ",IDC_STATIC,54,73,145,11
PUSHBUTTON "View Information",IDC_VIEW,254,165,56,16
Wat i want is instead of putting "Click View" in this file , can i declare a variable CString str_Data which gets its value from a function
smthng like str_Data = FetchData(LPCTSTR);
so wat i mean is :
LTEXT str_Data, IDC_STATIC,54,73,145,11
|
|
|
|
|
sorry for my poor English .
It can't use variable directly in Resource file . If you want to do that , you can use a static content which ID isn't IDC_STATIC , and use SetWindowText to contrl the static content that you want to display in the dialog CPP.
LTEXT "Select",IDC_STATIC_NAME,....
...
//dialog cpp
...
GetDlgItem(IDC_STATIC_NAME)->SetWindowText("...");
|
|
|
|
|
That's quite easy...
(Step 1) Change the ID of your static control to something other than IDC_STATIC . For example IDC_MY_TEXT .
(Step 2) You can set the text of your static control programatically at any place in your code (e.g. in OnInitDialog() ) with the following method:
SetDlgItemText(IDC_MY_TEXT, "Here goes your text!"); The text can surely be a CString instance or the return value of your getData() method.
cheers,
mykel
OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."
|
|
|
|
|
Thanx ....
n wat abt Resource File ... do i have 2 make sum changes in that ....
in LTEXT "",IDC_MY_TEXT,....
|
|
|
|
|
Sorry... what's your question? Please try to write valid English!
Perhaps you meant something completely different but... you don't have to change your resource file (.rc and/or resource.h) by hand. I guess you're using Visual Studio. Open the dialog that contains the static control, select the static with the mouse and enter the new ID for the static in the properties window. Press return, that's it. Visual Studion changes your resource files (.rc and resource.h).
Now you can use SetDlgItemText() to programmatically change the text of the static (see my previous post).
cheers,
mykel
OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."
|
|
|
|
|
I dont think you can open MSMQ with send & recv permissions simultaneously. but there are somethers= sharemode permissions you can check in MSDN.
|
|
|
|
|
Hi all,
i am making a sdi application in which i have made a static splitter control.
i have made 2 views to allocate to parts made by splitter control.i have derived those two classes from CListView and when i m using them in my code like this
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if (!m_wndSplit.CreateStatic(this,1,2))
{
TRACE(_T("failed to create the splitter"));
return FALSE;
}
if (!m_wndSplit.CreateView(0,0,RUNTIME_CLASS(CLeftList),CSize(225, 500),pContext))
{
TRACE(_T("Failed to create view in first pane"));
return FALSE;
}
if (!m_wndSplit.CreateView(0,1,RUNTIME_CLASS(CRightList),CSize(225, 500),pContext))
{
TRACE(_T("failed to create view in second pane"));
return FALSE;
}
return TRUE;
}
in my mainframe class it gives an error...
error C2504: 'CListView' : base class undefined
E:\Documents and Settings\Neha\Desktop\testapp\LeftList.cpp(17) : error C2440: 'return' : cannot convert from 'class CLeftList *' to 'class CObject *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\Documents and Settings\Neha\Desktop\testapp\LeftList.cpp(17) : error C2653: 'CListView' : is not a class or namespace name
and many more
what is the problem??
can anybody help me in this....
Thanks in advance
|
|
|
|
|
CListView is declared in "afxcview.h", check the whether your stdafx.h included afxcview.h.
|
|
|
|
|
It was not there not included and my problem is solved
thank you very much....
|
|
|
|
|
tell me one thing if i derive this class from CFormView and place a Listcontrol from control pane, Size of list control is not same as window and when i slide splitter control ii does not increase or decrease its size. can you tell me how to relate this list control to splitter bar...
|
|
|
|
|
I guess your the list control becomes the child of CFormView. Then if you want to adjust the size of list control, you have to handle the WM_SIZE, ... messages from CFormView and Adjust the list control size using SetWindowPos(). When you move the split bar the CFormView derived class will receive the Size messages.
Best Regards
Raj
|
|
|
|
|
Is there a way through which i can OR entire contents of array.
or may be some memory function which will or two pointers with the specified size.
|
|
|
|
|
And what exactly is wrong with using a loop for this purpose? I'm not exactly sure what you want to OR, but if you want to perform bitwise operations on the two numeric arrays, looping and storing the data in another array is a perfectly fine way of doing so.
|
|
|
|
|
Being arrays hugh loop takes 4-5 seconds.
so i want to reduce this time to 2-3 seconds.
|
|
|
|
|
Well, what I don't understand is... looping is a concept, so it's not inherently slow unless your algorithm is crappy. If you have 100 pieces of data, and you want to process them all, you have to create a loop that goes through everyone of them. An array (to my inexperienced self), is quite a simple data structure, basically, an initial value and offsets of size sizeof(type), all contiguous in memory, which should be very fast to access. You only have to loop through all of this data once. You do not have to revisit them. Just something like:
int array_A[100];
int array_B[100];
int array_C[100];
for (int i = 0; i < 100; i++)
{
array_C[i] = array_A[i] | array_B[i];
}
I don't know if it gets any simpler than that...correct me if I'm wrong.
|
|
|
|
|
I dont know whether i am looking for is possible or not?
what i want e.g if i have to assign 10000 elelemts in loop will take siginifancatly more time than a memcpy or memmove call. similarly something like memcpy or memmove is there anything that can speed up this or operation.
|
|
|
|
|
How huge of a loop takes 4-5 seconds???
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|