Hola a todos. Estoy desarrollando un editor de textos y quiero aprovechar el componente freeware TMapStream que implementa la técnica de mapeado de ficheros en memoria en forma de stream. Quisiera utilizarlo en la función de callback del mensaje EM_STREAMIN del richedit, pero o bien no me lee los archivos o bien los lee por la mitad, con la excepción pertinente de que no puede leer más allá del fichero. ¿Alguien sabe algo de esto?
Muchas gracias por anticipado.
1 respuesta
Respuesta de antipauli
1
1
antipauli, Analista/Programador de Sistemas Oracle
Ok, ahora te lo envío.
¿Puedes enviarme el código a [email protected]? En tu respuesta no aparece todo el código. Muchas gracias.
Muchas gracias. Me ha sido muy útil.
Aquí tienes una utilidad que puede que te sea de ayuda. Saludos, Antipauli unit CR_UORichEdit; { Enhanced TRichEdit support for DelphiDrop by UnitOOPS SOftware. Last Modified: 05/04/99 } interface uses Windows, Messages, Controls, Classes, ComCtrls; type // A TRichEdit descendant that exposes a published RTF property, to support DFM // persistence for the RTF in a TRichEdit. This also allows you to make changes // that recreate the window handle (e.g., changing the scrollbar settings at // design time) and retain the rich text, even if the control's contents are // modified at run-time. TUORichEdit = class(TRichEdit) private FRTF: string; procedure UpdateRTF; procedure SetRTF(const aRTF: string); protected procedure CMRecreateWnd(var Message: TMessage); message CM_RECREATEWND; published property RTF: string read FRTF write SetRTF; end; // Helper functions that do the actual RTF manipulations. procedure AddContentToRichEdit(aRTFString: string; aRichEdit: TCustomRichEdit; isRTF: boolean; insert: boolean); function GetContentFromRichEdit(aRichEdit: TCustomRichEdit; asRTF: boolean; selectionOnly: boolean): string; implementation uses SysUtils, RichEdit; procedure TUORichEdit.UpdateRTF; // Update the RTF from the private FRTF begin // Clear out the rich edit Lines.Clear; // Use the helper function to add the content. AddContentToRichEdit(FRTF, Self, true, true); end; procedure TUORichEdit.SetRTF(const aRTF: string); // Property setter for RTF. Only update things if changed. begin if (AnsiCompareStr(aRTF, FRTF) <> 0) then begin FRTF := aRTF; UpdateRTF; end; end; procedure TUORichEdit.CMRecreateWnd(var Message: TMessage); // This is the main raison d'etre for the TUORichEdit. Without this, every time // the window handle is destroyed, the rich text is lost, and only the plain // text remains. We catch the notification of window recreation, do the inherited // stuff (actually allow it to be recreated), then put the RTF back in. begin // We have a handle - pull the RTF out of the control, as it may have been changed // by the user. We store it temporarily so it can survive handle recreation, // then add it back. if (WindowHandle <> 0) then begin FRTF := GetContentFromRichEdit(Self, true, false); end; // If there's no handle, we're being created for the first time, // so we'll add the RTF already stored in the RTF property. // Do the handle recreation inherited; // Now put the RTF back. UpdateRTF; end; function EMStreamInCallback(dwCookie: Longint; pbBuff: PByte; cb: Longint; var pcb: Longint): Longint; stdcall; // Callback function for EM_STREAMIN handling. // This code, and the following "AddRTFToRichEdit" procedure based on corrected // versions of code examples by Ralph Friedman (TeamB). var theStream: TStringStream; begin // dwCookie is Application-defined, so we're passing the stream containing // the formatted text to be added. theStream := TStringStream(dwCookie); result := 0; with theStream do begin // Deal with the precise case where we get to the end of the buffer. // Happens for very small buffers (probably never for RTF due to all of the // junk that surrounds the smallest piece of RTF), but definitely for text! // This case was missing from the original code. if (Size = position) then begin pcb := 0; exit; end; if (Size - Position) <= cb then begin pcb := Size; Read(pbBuff^, Size); end else begin pcb := cb; Read(pbBuff^, cb); end; end; end; procedure AddContentToRichEdit(aRTFString: string; aRichEdit: TCustomRichEdit; isRTF: boolean; insert: boolean); // This code, and the preceding "EMS