Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
It is very difficult to answer your question without knowing details of the application but by a quick check of the respective parameters on the datasheets I would say that you could replace the IRF540 with an IRF640 but you could not replace an IRF510 with an IRF640.
But you could try replacing an IRF510 with an IRF640. It will do no harm and, depending on the circuit, may well work.
The gate threshold voltage at 4V is the same for all three NMOSFETs, so the DC conditions will not be affected.