Page 1 of 1

RvHtmlViewImporter with C++ Builder XE

Posted: Sat Jul 16, 2011 10:19 pm
by nachbar
I installed THtmlViewImporter under C++ Builder XE without too much trouble, as indicated here: http://nachbar.name/blog/2011/07/16/com ... uilder-xe/

However, I am having trouble getting RvHtmlViewImporter to build with C++ Builder XE

Can you tell me how to get RvHtmlViewImporter working with C++ Builder?

Thanks!

Posted: Sun Jul 17, 2011 7:48 am
by Sergey Tkachenko
What problems with RvHtmlViewImporter do you have?
Did you have problems installing it or using in your applications?

Notes about using the GoogleCode's version of THTMLViewer.

RvHtmlViewImporter was tested with THTMLViewer 11 revision 168. Probably it can work with newer revisions. If not, let me know (specifying the exact text of the compiler error message).
When downloading from SVN, THTMLViewer 11 can be found in "branches\11" (do not use the versions from "trunk" or "tags"!).

Before installing RvHtmlViewImporter, open rvHtmlViewImport.pas and make sure that GOOGLECODE is defined
(the file must have the line {$DEFINE GOOGLECODE}; if not, probably you use a wrong (old) version of RvHtmlViewImporter).
Create a new C++Builder package, save it as rvHtmlViewImportCBXE.cbproj. Add rvHtmlViewImport.pas in this package. Add RVPkgCBXE.bpi and <THTMLViewer package name>.bpi in "requires" if this package (right click "Requires" in the Project Manager, choose "Add Reference"). Save the package and install it.
Then add the path where rvHtmlViewImport.obj is created to "Tools | Options", "Environment Options | C++Options | Paths and Directories | Library path".

PS: the trick with creating a new package using Install | Component described in that article is new to me, and the option for generating all C++ files for Delphi package does not work in RAD Studio XE for me, what's why we created separate Delphi and C++ packages. I'll investigate it later...

PPS: one important thing. Since RVPkgCBXE.cbproj has the option "Explicit rebuild" (Project | Options, Descriptions), the both HTMLViewer's and rvHtmlViewImporter's package must have this option as well. Otherwise the compiler will show an error like "never-build package XXX requires always-build package YYY".

Posted: Sun Jul 17, 2011 7:43 pm
by nachbar
Thanks for the tips! Using those, I was able to get rvHtmlViewImporter to work.

Thanks for explaining where the Explicit Rebuild option was set -- I could not find that before, and did not think to look under "Description" (which is not really what a "Build Option" is). Explicit Rebuild was set as the default for these new C++ Builder Projects, so I did not have to change it.

I did not mean to imply that "Generate all C++ files" would allow the components to work under both Delphi and C++. If you know how to get the components to work under both Delphi and C++ in RAD Studio, I hope you will tell me.

The "Install | Component" technique has flaws under C++ (it works a lot better with Delphi than C++ Builder), because it starts the build before you have finished the options, and when it hits a problem, it just fails. Under Delphi, it actually fixes the problem and restarts the build.

Using branch/11 instead of trunk, the sample Hello World project for THtmlViewer no longer needs to use WideString, just:

Code: Select all

HtmlViewer1->LoadFromString("Hello");
Notes for anyone finding this post in the future (including me, the next time I have to upgrade):


For those of us who don't use svn, you can check what branches are available with

Code: Select all

svn list http://thtmlviewer.googlecode.com/svn/branches
Branch 11 is the only one at this writing.

At this time (17 Jul 2011), the latest revision in branch/11 is r171 from 3 Apr 2011, which worked.

To see what revisions are available for a branch:

Code: Select all

svn log (branch name, or . if you have checked out a branch) | less
I found the RVPkgCBXE.bpi in C:\Users\Public\Documents\RAD Studio\8.0\Dcp

As you had noted, the TRichView source directory needs to be added to the library path, for RVTable.res (and others)

The C++ version of Hello World for RVHtmlViewImporter is:

New C++ Project, drop a TRichViewEdit, TRVStyle, TRVHTMLViewImporter, and a THtmlViewer on the form. In the FormCreate:

Code: Select all

RVHTMLViewImporter1->HTMLViewer = HtmlViewer1;
RichView1->Style = RVStyle1;
HtmlViewer1->LoadFromString("Hello");
Create a button, and for its click handler:

Code: Select all

RVHTMLViewImporter1->ImportHtmlViewer(RichView1);
RichView1->Format();
Start the program. You should see "Hello" in the HTMLViewer. Click the button, and you should see "Hello" in the RichViewEdit. If you get an access violation when you click the button, you forgot to hook up the TRVStyle component.