Custom module with custom node type, error Trying to get property of non-object en comment_node_type_delete()
I believe the problem is that it's expecting an object, and you are passing a string. Try changing this:

node_type_delete($ournewtype);


To this:

$node_type = node_type_load($ournewtype);
node_type_delete($node_type);


One other thing, instead of this:

$result = db_query($sql, array(':type' =&gt; $ournewtype));
$nodeids = array();
foreach ($result as $row) {
    $nodeids[] = $row-&gt;nid;
}


You can simplify it by using this:

$nodeids = db_query($sql, array(':type' =&gt; $ournewtype))-&gt;fetchCol();