The evolution of the internal distribution of lithium and beryllium in the envelopes of nonrotating Population I A and F stars is computed for the whole main-sequence lifetime of the stars. The calculations include the effects of changing envelope structure due to core evolution and helium gravitational settling, convective mixing, nuclear burning, and diffusion in presence of radiative forces and dragging by the main gas constituents. The new OPAL opacities are used. Since adjustable parameters were calibrated using the Sun, the calculations presented here are entirely from first principles. The formation of a stable subsurface reservoir (sometimes two reservoirs in the case of Be) and later dredge-up from that reservoir are identified as the main mechanism controlling the surface abundance of lithium and beryllium in these stellar models. This phenomenon should be a generic one among hot stars, for many other trace elements, including Fe. The position and depth of the calculated Li abundance gap is consistent with the observed Li gap in several open clusters. It is however, narrower than the observed gap. Similar calculations using the 1977 opacities of Huebner et al., and independently calibrated, do not produce a deep enough gap. A "beryllium gap" is also predicted and is consistent with the observations in the Hyades.