I think such questions are (generally speaking) excellent, and should in no way be discouraged. In particular, they're vastly preferable to the all too common questions where the askers, instead, omit all mention of their actual goal X and just write "I'm trying to do Y but it's not working the way I want! Can anyone help me?"
Note that, in most of the questions you've cited, the asker is not actually proposing a real answer to their problem in the question; rather, they're either describing a failed answer that is not solving their problem, or they only have a vague and incomplete sketch of an answer and are asking whether and how it could be turned into a real solution.
Basically, by including their own (unsatisfactory) attempt at an answer in their question, these askers are telling us what they've tried so far, something our FAQ explicitly encourages (emphasis mine):
Do your homework
Have you thoroughly searched for an answer before asking your question? Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer!
Of course, I'm sure there exist some questions that do, in fact, contain or presuppose their own answer and would benefit from the measures you suggest (moving the answer out of the question, or closing as "not constructive" or "not a real question"). I'm just saying that I don't think any of the examples you've listed above really are such questions.
I should also note that the meta.SO post you linked to in the comments (or at least the accepted answer to it) is mostly about something else, namely about situations where the asker, after having asked a more or less valid question, later finds an answer but posts it as an edit to their question rather than as an answer to it. That's really more of an issue of new users being confused by the Stack Exchange user interface than a case of actual inappropriate questions.