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开发者_StackOverflow社区 (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;
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 the SetString
function call):
while not ADOStoredProc.Eof do
begin
Memo1.Lines.Add(ADOStoredProc1.FieldByName('Report').AsString;
ADOStoredProc1.Next;
end;
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 the EM_STREAMIN
message to add the content, and then use the TRichEdit.PlainText
property. There's an example of doing that here.
精彩评论