Assert failed in OnInitDialog() - c++

So I have an "assertion failed" error message when I want to run my program. I understand that it means that somewhere a condition that should be true isn't but I don't know how to correct that.
The error concerns the following line :
_AFXWIN_INLINE BOOL CEdit::SetReadOnly(BOOL bReadOnly)
{ ASSERT(::IsWindow(m_hind)); return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L); }
So I get that it's about the "Read Only" condition, but I don't know where to correct that.
I am new in C++, so sorry if I forgot to put important information in my question.
Thanks in advance!

The OnInitDialog function contains a call to the base class function
CDialog::OnInitDialog();
Move your calls to SetReadOnly to after that line. The edit control variables are only initialized after that line.

Thank you for your help! Finally, after going through the whole code line by line, I realized in DoDataExchange I mixed up and put twice the same variable at some point instead of two different ones ... So I don't really know how that got me that error but I thought I'd keep you updated in case someone makes the same absent-minded mistake and gets that error :)

Related

"Expected Declaration" Error on Delegate Function Call

Xcode 8/Swift 3
Can anyone please tell me why I am getting this "expected declaration" error? The use of delegates answered my last question perfectly without getting this error.
Googling other "expected declaration" problems suggests function calls etc being in the wrong place but I don't think thats the case here - I have tried placing delegate?.loadFirstView(viewFromModel: firstView) in a separate function and then calling that function but I just get the same error. See the screenshot below:
Thanks in advance!
P.S: below is a screenshot of when my use of a delegate worked perfectly.
Third Screenshot with delegate call in a separate function:
You have the code (delegate?.loadFirstView(viewFromModel : firstView)) in the wrong place in the class. So move it to any function.
In your working screenshot, the code is written inside the updateClock()method, thus working without any error.
class modelClass{
var delegate : LoadFirstViewProtocol?
let firstView = "First view loaded"
func testing()//Write here user defined method named
{
delegate?.loadFirstView(viewFromModel: firstView)
}
}

WTL CListViewCtrl getSelectedItem is causing an Assertion fail for me

This is my code in order to get the name of the item which has been selected in my CListViewCtrl:
LVITEM item = { LVIF_PARAM };
CString itemText;
clistViewCtrl.GetSelectedItem(&item);
clistViewCtrl.GetItemText(item.iItem, item.iSubItem, itemText);
Note that this code is working. I recently did another project, where I grabbed the name in exactly this way, however, I had no problems there with any assertion fails.
When I execute this with my current project, I always get a debug assertion:
"File: ... atlctrls.h"
Line: 3242
Expression: (GetStyle() & 0x0004) != 0
Even though the expression already states it pretty much, here is the line causing the failure:
ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
I have barely any idea what the problem is. As I said, the exact same code worked on my other project, and I just went through both, trying to find any differences which could cause this behaviour, but nothing caught my eye.
Honestly, I don't even know if this is related to my code at all, considering the two compared elements seem to be predefined.
My first guess would have been that this part is being called before the items are created, but all items in the listview are created at the point I try to call this code passage.
Can anyone point me to a solution?
Your control is not created with style flag LVS_SINGLESEL. So calling GetSelectedItem is causing an assert. In case of multi selection use GetFirstSelectedItem and GetNextSelectedItem instead of GetSelectedItem. For single selection you can continue useing GetSelectedItem, but you have to add LVS_SINGLESEL style flag to your control.

Error: Variable "BOOL" is not a type name

I am trying to create a very simple MFC application when suddenly Visual Studio decides it no longer recognizes what a BOOL is.
I cannot figure out why this is happening. Does anyone know why this is going on and how to fix it?
It looks like you're missing a closing semi-colon at the end of your class.
class CApp : public CWinApp {
...
}; <---
This is the proper class syntax. I'm sure you know that and just happened to delete it and missed the simple error. I would say when you look at the error report it's best to solve the topmost one first. Doing so can eliminate other errors in the list especially in the case of a ;. Your image reflects that on the first line where it tells you about a missing ;.

What has to be Glib::init()'ed in order to use Glib::wrap?

So I'm trying to make use of a GtkSourceView in C++ using GtkSourceViewmm, whose documentation and level of support give me the impression that it hasn't been very carefully looked at in a long time. But I'm always an optimist :)
I'm trying to add a SourceView using some code similar to the following:
Glib::RefPtr<gtksourceview::SourceLanguageManager> source_language_manager = gtksourceview::SourceLanguageManager::create();
Glib::RefPtr<gtksourceview::SourceLanguage> source_language = Glib::wrap(gtk_source_language_manager_guess_language(source_language_manager->gobj(), file, NULL));
Glib::RefPtr<gtksourceview::SourceBuffer> source_buffer = gtksourceview::SourceBuffer::create(source_language);
gtksourceview::SourceView* = m_source_view = new gtksourceview::SourceView(source_buffer);
m_vbox.pack_start(*m_source_view);
Unfortunately, it spits out the warning
(algoviz:4992): glibmm-WARNING **:
Failed to wrap object of type
'GtkSourceLanguage'. Hint: this error
is commonly caused by failing to call
a library init() function.
and when I look at it in a debugger, indeed the second line above (the one with the Glib::wrap()) is returning NULL. I have no idea why this is, but I tried to heed the warning by adding Glib::init() to the begining of the program, but that didn't seem to help at all either.
I've tried Google'ing around, but have been unsuccessful. Does anyone know what Glib wants me to init in order to be able to make that wrap call? Or, even better, does anyone know of any working sample code that uses GtkSourceViewmm (not just regular GtkSourceView)? I haven't been able to find any actual sample code, not even on Google Code Search.
Thanks!
It turns out, perhaps not surprisingly, that what I needed to init was:
gtksourceview::init();
After this, I ran into another problem with one of the parameter to gtksourceview::SourceLanguageManager, but this was caused by a genuine bug which I subsequently reported and was promptly fixed. So everything's working great now!
I use gtkmm. Typically you have to initialize things with something like :
_GTKMain = new Gtk::Main(0, 0, false);
Of course do not forget :
delete _GTKMain;
Check here for details :
http://library.gnome.org/devel/gtkmm/2.19/classGtk_1_1Main.html
(Sorry but the link option does not work ...)

Error while calling member function

Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working.
The error is:
Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type
EDIT: The Code is:
void function ()
{
if (1001->Checked)
{
Sleep(2000);
}
}
Without seeing some of your code, it's very difficult to offer targeted assistance.
However, that error message usually comes about because the item you're de-referencing is not a pointer.
Check to ensure it's of the correct type. It should be something along the lines of:
tCheckBox *CheckBox1;
One possibility is that you've declared it not as a pointer to the checkbox but as a checkbox itself:
tCheckBox CheckBox1;
Note the lack of the asterisk there that would otherwise mark it as a pointer. In that case, you would use CheckBox1.Checked rather than CheckBox1->Checked, if it's allowed by the framework (this isn't standard C++ since that beast has no concept of GUI libraries).
If that doesn't help, please post the code so we can offer better suggestions.
Update:
if (1001->Checked) ?????
1001 is not a pointer - it's not a variable of any description, it's an integer constant.
You need to declare and use a variable of some description. First step is, I think, to read up on the documentation for your framework and/or get some sample code that does compile and work, basing your initial work of that.
Use CButton::GetCheck() to determine the state of the checkbox - like so...
CButton* pButton = (CButton*) GetDlgItem(IDC_CHECKBOX_RESOURCE_ID);
if ( BST_CHECKED == pButton->GetCheck() )
{
// button is checked
}