We study the physical mechanism of Maxwells Demon (MD) helping to do extra work in thermodynamic cycles, by describing measurement of position, insertion of wall and information erasing of MD in a quantum mechanical fashion. The heat engine is exemplified with one molecule confined in an infinitely deep square potential inserted with a movable solid wall, while the MD is modeled as a two-level system (TLS) for measuring and controlling the motion of the molecule. It is discovered that the the MD with quantum coherence or on a lower temperature than that of the heat bath of the particle would enhance the ability of the whole work substance formed by the system plus the MD to do work outside. This observation reveals that the role of the MD essentially is to drive the whole work substance being off equilibrium, or equivalently working with an effective temperature difference. The elaborate studies with this model explicitly reveal the effect of finite size off the classical limit or thermodynamic limit, which contradicts the common sense on Szilard heat engine (SHE). The quantum SHEs efficiency is evaluated in detail to prove the validity of second law of thermodynamics.