将 RTF 图像数据转换为纯文本(SQL Server 和 Dephi BDS 2006)
一直在这个问题上挣扎了一段时间。我们有一个包含图像类型数据的旧表(SQL Server)。我想获取文本。
到目前为止,这就是我所做的。
- 尝试转换或转换它(不允许)
- 尝试通过调用SP将数据带入delphi(我已经到了将数据分配给变体的地步)
- 研究了RTF到文本函数(在SO上找到了一些东西) ,如果我可以将图像数据放入字符串中)。
这是我到目前为止的代码。它现在附加到按钮单击(将在服务中运行)。我认为对report var的赋值不正确,SetString也可能不正确。我什至不确定我是否以正确的方式处理这件事。
var
report: array of byte;
s: string;
begin
ADOStoredProc1.Parameters.ParamByName('@EncounterID').Value := '7';
ADOStoredProc1.Open;
while not ADOStoredProc1.EOF do
begin
report := ADOStoredProc1.FieldByName('Report').Value;
SetString(s, PAnsiChar(@report[0]), length(report));
Memo1.Lines.Add(s);
ADOStoredProc1.Next;
end;
Been struggling with this one for a while. We have a old table (SQL Server) that has image type data. I want to get the text.
So far this is what I've done.
- Try to convert or cast it (not allowed)
- Try to bring over the data into delphi by calling a SP (I got to the point of having the data assigned to a variant)
- Looked into a RTF to text function (found something here on SO, if i can just get the image data into a string).
This is the code I have so far. It's attached to a button click for now (will be running in a service). I think the assignment to the report var is not right, and SetString may not be right either. I'm not even sure if i am going about this the right way.
var
report: array of byte;
s: string;
begin
ADOStoredProc1.Parameters.ParamByName('@EncounterID').Value := '7';
ADOStoredProc1.Open;
while not ADOStoredProc1.EOF do
begin
report := ADOStoredProc1.FieldByName('Report').Value;
SetString(s, PAnsiChar(@report[0]), length(report));
Memo1.Lines.Add(s);
ADOStoredProc1.Next;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对“RTF 图像”有点困惑。你的意思是RTF文本吗?还是图像(图片)?从代码中,我怀疑前者......
我不确定为什么你使用字节数组,然后立即将其放入字符串中。
这应该同样有效(实际上,更好,因为它不使用
Value
(这是一个 Variant 转换)并避免SetString
函数调用):不过,可能可以通过这种方式在备忘录中获取 RTF 格式。如果您尝试删除格式,则需要使用
TRichEdit
,并使用EM_STREAMIN
消息添加内容,然后使用TRichEdit.PlainText
属性。 此处有一个执行此操作的示例。I'm a little confused by "RTF image". Do you mean RTF text? Or an image (picture)? From the code, I'm suspecting the former...
I'm not sure why you're using an array of byte and then immediately putting that into a string.
This should work just as well (actually, better, because it doesn't use
Value
(which is a Variant conversion) and avoids theSetString
function call):You'll probably get the RTF formatting in the memo this way, though. If you're trying to strip the formatting, you'll need to use a
TRichEdit
instead, and use theEM_STREAMIN
message to add the content, and then use theTRichEdit.PlainText
property. There's an example of doing that here.