Cannot Display BLOB From MS Access Database

General TRichView support forum. Please post your questions here
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Cannot Display BLOB From MS Access Database

Post by fchintc »

Hi,

I am evaluating TRichview 1.9.24 with D7 and am connecting it to a MS Access database. All I am seeing in the edit box are a bunch of squares and letters.

How can I display the contents properly?

Thanks.

Fred
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

What field type do you use? Probably it cannot contain binary documents.
Try to set TDBRichViewEdit.FieldFormat = RTF.
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

I was using TRichView previously but I changed to TDBRichViewEdit (with FieldFormat set to RTF) and the result is still the same; boxes and letters.

Using MS Access, I see that the field is a Long Binary Data type.


Fred
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please send me a test project with test database.
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Hi,

I have sent the test project to your e-mail account of [email protected].

Thanks.

Fred
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Your database has data in strange format - RTF converted to Unicode (WideString). TDBRichViewEdit does not understand it, so it reads it as a plain text, and you can see RTF codes (with space character between each RTF character).
You can use OnLoadCustomFormat event to display such fields in TDBRichView/TDBRichViewEdit:

Code: Select all

procedure TForm1.DBRichViewEdit1LoadCustomFormat(Sender: TCustomRichView;
  Stream: TStream; var DoDefault: Boolean);
var ws: WideString;
    Stream2: TStringStream;
begin
  if Stream.Size mod 2 = 0 then begin
    SetLength(ws, Stream.Size div 2);
    Stream.ReadBuffer(Pointer(@ws[1])^, Stream.Size);
    if (Length(ws)>5) and
       (ws[1]='{') and (ws[2]='\') and (ws[3]='r') and (ws[4]='t') and (ws[5]='f') then begin
      Stream2 := TStringStream.Create(ws);
      DoDefault := not Sender.LoadRTFFromStream(Stream2);
      Stream2.Free;
    end;
  end;
end;
But after editing, they will be saved back as normal RTF (if FieldFormat=RTF) (well, it's possible to save this "widestring RTF" using OnSaveCustomFormat event, but I think it makes no sense)
In addition, make the following changes:
1) Right click DBRichViewEdit1, choose "Settings" in the context menu, make sure that "Allow adding styles dynamically" is set.
2) Set DBRichViewEdit1.AutoDeleteUnusedStyles = True
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Thank you very much for your help. The database is from an application written in VB and I am converting it to be stored in DBISAM. The contents display correctly now. I will test TRichview on the entire database of 1,267 records and see if anything else crops up.

I will keep in touch on the status of my tests.

Fred
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Hi,

Further to your suggestion to allow display of BLOB field from MS Access, I have converted the database contents from MS Access to DBISAM.

The following line:-

if Stream.Size mod 2 = 0 then begin // mod 1 required for DBISAM Table

cannot be used for displaying DBISAM tables because in DBISAM, the Stream.Size is not an even number. I changed the "mod 2" to "mod 1" and the display is possible. Even "mod 1" can be used for displaying MS Access tables without ill effects. Is using "mod 1" OK?

The other problem is that for one record in MS Access (or DBISAM), the program crashes with an "Index out of bounds" error when the answer field is displayed. Is it possible for you to check why this is happening? Is it a data corruption problem? If yes, can it be trapped? I have sent you the test project files.

Thanks.

Fred
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As for the exception.
Link each DBRichViewEdit to its own TRVStyle object. The error happens because when the second editor loads from DB, it replaces collection of text, paragraph and list styles in RVStyle1, and the first editor cannot use them to display its document.

As for DBISAM.

So this conversion is not correct, it adds an extra character to data.
Ok, you can change this condition for DBISAM table, it should not do harm. But I'd recommend to convert the whole table to normal format:

Code: Select all

adoQuestion.First;
while not adoQuestion.EOF do begin
  adoQuestion.Edit;
  DBRichViewEdit1.Change;
  DBRichViewEdit2.Change;
  adoQuestion.Post;
  adoQuestion.Next;
end;
After this conversion, you can remove OnLoadCustomFormat at all.
This conversion loads documents in each record in DBRichViewEdits and resaves them. Documents will be resaved in formats specified in DBRichViewEdit1.FieldFormat and DBRichViewEdit2.FieldFormat
(if they are rvdbRTF, it will be saved as RTF, if they are rvdbRVF, they will be saved in native TRichView format).
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Thank you for the quick answers!

I will perform the edit and save function for each record in DBISAM since this will be the final database that will be used in the new program. Also, I will create another TRvStyle and link to the second edit.

I will have the client give me all the remaining MDB databases to test and if everything turns out fine, I will purchase TRichView next week.

Thanks again.

Fred
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Hi Sergey,

I have imported another MDB database but there is a problem with displaying pictures. Instead of a picture, I see a small icon where it should be.

I would appreciate it if you could look at the sample project files I have e-mailed to you. Look at the part just below the line that says:-

"The diagram below shows a telescope"

Another thing is the question field actually has grid lines that don't print out but are faintly visible to align the contents of the question. Can TRichview display them?

Thanks.

Fred
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This image is in PNG format.
PNG graphic class is not included in Delphi, but you can download free thirdparty implementation from http://pngdelphi.sourceforge.net/
After that, include CRVData, PngImage in "uses", and add initialization section to your unit:

Code: Select all

initialization
  RV_RegisterPngGraphic(TPNGObject);
This code will allow TRichView to load and save PNG image in RTF.
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Thanks for the tip! The PNG image is displayed correctly when using the MDB database. However...

When I have PNGDelphi used in a unit with DBISAM 4, Delphi 7 will complain with the following error message:-

Unit Zlibcomp was compiled with a different version of zlibpas.z_errmsg

What is happening is DBISAM has a Zlibcomp.pas unit that uses its own Zlibpas.pas unit. PNGDelphi has PNGdelphi.pas using its own version of Zlibpas.pas.

How can I use both DBISAM and PNGDelphi together?

Thanks.

Fred
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Hmm... try to remove one of them, I believe they are the same, so you can use the newer one.
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Hi Sergey,

I managed to get PNGDelphi to run with DBISAM by renaming the Zlibpas.pas file used by PNGDelphi and references to another name. (With help from Elevatesoft, the vendor for DBISAM)

In addition, I would like to thank you for the excellent technical support that you have provided during my evaluation process for TRichView! You can be sure that I will have more questions as I use TRichview more.

I am pleased to let you know that I am placing an order for TRichview. Also, I would like to get the discount for Addict speller. Do I get the discount from your web site or from Addictive's web site?

Thanks.

Fred
Post Reply