|
Currently there are no other observers, but some day they might be.
The main problem is not deleting the object, but breaking the notification loop.
How do I accomplish that ?
|
|
|
|
|
Hi,
could't it be done like this ?
...
5. in some point of the flow, an object from step two decided it is finished. it notifies it's observer from step 4.
6. the observer from step 4 performs some action based on the received notification and then returns a "special value" meaning that the object has to delete itself.
7. the calling object receives the "notification's return", and if it is the "special value", it deletes itself...
Lion.
|
|
|
|
|
What do you mean by "6. the observer.... returns a "special value"...."
I don't know of any way an observer can return something to the notifying subject. That's not how my Observer pattern is implemented..
Any other idea ?
Thanks.
|
|
|
|
|
The observer could notify the singleton that it is "finished" with the object. The singleton could then decide what to do - it would probably pass on the message to the object, which would inform other interested observers of the fact. The object can then delete itself. If it does so, it should inform its (other) observers that it's no longer available for use.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
All is well, but it doesn't change the fact that it still does't break the notifications loop.
Think of this as the flow of events:
1. Subject starts it's notification loop
2. it reaches my observer is the list of observers and notifies it
3. the observer then notifies the singleton needs to be deleted
4. the object is deleted
5. the function (in the singleton and in the observer) returns and the next thing to do is for the subject to continue it's notification loop on to the next observer on the list, but then the program crashes on access violation since the memory space the subject has occupied is not longer allocated since it was deleted / has deleted itself.
Please try something else.
Thanks,
Lior.
|
|
|
|
|
check out my reply to the previous message I received.
In short, it still doesn't break the notifications loop.
Thanks,
Lior.
|
|
|
|
|
IMHO there's a conceptual mismatch here that's causing your problems: You have an observer entitled to delete the subject (so it is a rather powerful observer) but that might be sharing the observation with other observers. The design seems to fail to capture the special role played by this observer. Maybe you can transfer the responsibilty of deleting subjects to the singleton class that holds them, and keep the observers as passive objects, which is (as I see it) what this design pattern originally intends.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'm getting the error message:
'Cx::Cx' : cannot access protected member declared in class 'Cx'
I used the classwizard to create a CWinThread derived class Cx.
And I see that i places the construtor in the protected section.
Now I read that there were two ways to start the thread, one that uses AfxBeginThread /ResumeThread and this one:
Cx * thread = new Cx();
thread->m_x = 1;
thread->CreateThread();
I like this implimentation and would like to get it to work but I'm not sure how.
|
|
|
|
|
Anonymous wrote:
And I see that i places the construtor in the protected section
You placed your constructor in the protected section or the class wizard did?
It seems to me that the contstructor should be in the public section.
|
|
|
|
|
Thats a typo, the sentance should read:
And I see that IT places the construtor in the protected section.
it = classwizard.
>It seems to me that the contstructor should be in the public section.
Yeah, thats what i thought (which is why i included that bit of info about the location of the constructor) but thats what the classwizard does so i don't want to go and change it.
So my question in the first post still stands.
|
|
|
|
|
I am not a big MFC programmer, but MSDN says that AfxBeginThread will create the instance of the object for you.
|
|
|
|
|
I can't believe this trivial/basic task is giving me trouble! I've figured pretty much everything else out -- but .. in VC++.NET how do you properly delete a classes member functions and variables?
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
Appart from any other IDE-assisted methods, you can always go to the corresponding .h and .cpp files and manually erase the occurrences of the member.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That's what I am doing now. I'm simply wondering where the IDE assisted feature for it is ..
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
Yes, I should have guessed. I don't know, I'm sorry I can't be more helpful.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
I have been looking all over the web(or at least as far as google takes you) for the source of a tab view. All i need are these nice Execl like tabs. I found some source on the codeproject for something similar, but these flicker way too much to be usefully.
Does anyone have an idea, where I can get a source for a Tab-view.
Thank You,
SD
|
|
|
|
|
|
I need help with showing me how to draw a bitmap that i have in the resources, into my application upon run time. CAn someone help me out and explain in detail please. Thanks
the meek shall inherit thee earth.......but they wont get the ball
|
|
|
|
|
If you want to draw the bitmap onto a window using a DC here is how you would do it:
PAINTSTRUCT ps;
HDC hdc;
hdc = ::BeginPaint(hWnd, &ps);
HBITMAP hBitmap;
::LoadImage(::GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_RESOURCEID),
IMAGE_BITMAP,
0,
0,
LR_DEFAULTSIZE
);
if (!hBitmap)
{
}
HDC memDC;
memDC = ::CreateCompatibleDC(hdc);
HBITMAP hBmpOld;
hBmpOld = (HBITMAP)::SelectObject(memDC, hBitmap);
BITMAP bm;
::GetObject(hBitmap, sizeof(BITMAP), &bm);
if (FALSE == ::BitBlt(hdc, 0,0, bm.bmWidth, bm.bmHeight, memDC, 0,0, SRCCOPY))
{
}
::SelectObject(memDC, hBmpOld);
::DeleteDC(memDC);
::DeleteObject(hBitmap);
::EndPaint(hWnd, &ps);
If you would like to paint a bitmap outside of the paint handler, you can replace the following code:
PAINTSTRUCT ps;
hdc = ::BeginPaint(hWnd, &ps);
...
::EndPaint(hWnd, &ps);
with this:
hdc = ::GetDC(hWnd);
...
::ReleaseDC(hWnd, hdc);
If you have any other questions, feel free to ask.
|
|
|
|
|
How can i pass a variant type data to a activex control in a mfc app?
the msdn says i need use COlevariant class, but how?
thanks for help
|
|
|
|
|
ALl you need to do is create a COleVariant object using the appropraite constructor, and either Detach it (to get a VARIANT) or use the LPVARIANT operator (to get a pointer to a VARIANT). For example, if you have an Automation function like:
HRESULT SomeFunction([in] VARIANT avtLabel, [in] VARIANT *apvtTimes);
you should be able to:
COleVariant vvtLabel(_T("My STring"));
COleVariant vvtInt(1000, VT_I4);
HRESULT vhRet;
vhRet = SomeFunction(vvtLabel.Detach(), vvtInt);
<pre>
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Thanks very much, that's would be very helpful.
|
|
|
|
|
Hi. Im starting de development of a new program and it will access files from a server protected directory, so it cant be accessed directly (except by admin). The program will be used by standart users, which, depending on their permissions, can only access some files. How can i access the directory from the program?
a) creating a user "administrator" that is actually the program (is that possible??)
b) Using a kind of FTP server that doesnt allow direct access, but allows authorized users to get the files
c) ...
|
|
|
|
|
How I can find if my application is running under debugger?
|
|
|
|