nugame
11-06-2007, 19:03:47
Hola:
Quisiera mover un fichero .rtf o .dot a un dberichedit pero al copiarlos me mete caracteres extraños y no hay manera.
¿Alguien sabe como podría mover al dberichedit esos tipos de ficheros?
Gracias
Perdon en el anterior tema puse rtl en vez de rtf...
loxod
13-06-2007, 19:03:28
yo he usado el siguiente codigo, pero uso un richediten vez de un dbrichedit
unit rtf2blob_u;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, DBCtrls, Db, DBTables, StdCtrls, ComCtrls,
richedit;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
OpenDialog1: TOpenDialog;
DataSource1: TDataSource;
Table1: TTable;
DBNavigator1: TDBNavigator;
procedure Button1Click(Sender: TObject);
procedure Table1AfterScroll(DataSet: TDataSet);
procedure Table1BeforePost(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
EditStream : TEditStream;
bs : TBlobStream;
L : Longint;
//solo para cargar un archivo rtf
procedure TForm1.Button1Click(Sender: TObject);
begin
if (table1.state = dsInsert) or
(table1.state = dsEdit) then
begin
If opendialog1.execute then
Richedit1.Lines.LoadfromFile(opendialog1.FileName);
end
else
Showmessage('El Dataset debe estar en modo de Edicion');
end;
Function MyEditStreamCallBackOut(dwCookie: Longint; pbBuff: PByte;
cb: Longint; var pcb: Longint): Longint; stdCall;
Begin
bs.WriteBuffer(pbbuff^,cb);
pcb := DWord(@L);
result := cb;
end;
Function MyEditStreamCallBackIn(dwCookie: Longint; pbBuff: PByte;
cb: Longint; var pcb: Pointer): Longint; stdcall;
var
dw : DWord;
Begin
pcb := @cb;
if cb > bs.Size - bs.position then
dw := bs.Size - bs.position
else
dw := cb;
if dw <> 0 then
bs.ReadBuffer(pbbuff^,dw);
result := 0;
dw := bs.position;
move(dw,pcb,sizeof(dw));
end;
//Obtiene el contenido del archivo rtf desde el campo BlobField
procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
begin
bs := TBlobStream.Create(TBlobField(table1.FieldByName('rtfBlob')),bmRead);
try
bs.Position := 0;
editStream.dwCookie := SF_RTF;
editStream.dwError := 0;
editStream.pfnCallback := @MyEditStreamCallBackIn;
Richedit1.Perform(EM_StreamIn,SF_RTF,DWord(@EditStream));
finally
bs.free;
end;
end;
//almacena el rft en el blobfield
procedure TForm1.Table1BeforePost(DataSet: TDataSet);
begin
bs := TBlobStream.Create(TBlobField(table1.FieldByName('rtfBlob')),bmWrite);
try
editStream.dwCookie := SF_RTF;
editStream.dwError := 0;
editStream.pfnCallback := @MyEditStreamCallBackOut;
Richedit1.Perform(EM_StreamOut,SF_RTF,DWord(@EditStream));
finally
bs.free;
end;
end;
end.
espero que te sirva
nugame
02-10-2007, 13:04:57
Hola:
Antes de nada gracias por tu ayuda.
El ejemplo que me enviaste me procude el error 'Invalid class typecast' en la línea...
bs := TBlobStream.Create(TBlobField(table1.FieldByName('rtfBlob')),bmWrite);
El campo en la tabla de la base de datos en un blob creado asi..:
rftBlob BLOB SUB_TYPE 2 SEGMENT SIZE 1
Es decir Tamaño de segmento 1, Subtipo 2
¿Estoy creando mal el campo blob?
Gracias por todo y disculpa
vBulletin v3.6.8, Derechos ©2000-2024, Jelsoft Enterprises Ltd.