TPrintPreview: custom form management

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

TPrintPreview: custom form management

Postby svens » February 15th, 2009, 1:01 pm

Hello!

I am currently trying to use the TPrintPreview unit to manage custom printer forms (Delphi 2009 on Vista Home Premium). While I was able to delete forms, I am not able to use AddNewForm as I was trying with:

Code: Select all
...
var
 previewtest : TPrintPreview;
 begin
    previewtest.AddNewForm('my_test', 10, 10);
...


It compiles, but throws an "EAccessViolation" exeption at

Code: Select all
  Size.cx := X * 10;


in

Code: Select all
function TPrintPreview.AddNewForm(const AFormName: String;
  FormWidth, FormHeight: DWORD): Boolean;


I guess, that I might have to call any other methods before adding a custom form, but I didn't find any hint so far. Btw. is it possible to give me a small example on how to use "FetchFormNames"?

Thanks!
/sven
svens
Member
Member
 
Posts: 2
Joined: February 15th, 2009, 12:31 am

Re: TPrintPreview: custom form management

Postby Kambiz » February 15th, 2009, 3:49 pm

To add/remove a printer from, user must have the required privileged. The PrintPreview component do not check the user rights, and it's your application that should do that.

On Windows Vista when UAC is enabled, even an administrator has the same rights of a limited user and this may cause problem. Please turn off UAC and see whether still exception occurs. To do so, go to Control Panel > User Accounts > Turn User Account Control on or off.

I have Vista with UAC off, and I can add/remove forms with no problem.

The following line of code fills a combobox with form names:
Code: Select all
PrintPreview.FetchFormNames(ComboBox1.Items);
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview: custom form management

Postby Kambiz » February 15th, 2009, 4:04 pm

By the way, I don't think not having enough privilege cause AV. In this case, the function should return false with no exception.

Did you drop the component on a form? Or, do you create an instance of the component?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview: custom form management

Postby svens » February 15th, 2009, 4:20 pm

I just tested it by turning UAC off (working as admin) - the same result - whenever I want to add a new form, it throws the same exception :-(
Removing a form works, also worked before while having UAC on.

Any idea?
Do I have to initialize something before adding a new form? Or is a simple AddNewForm enough?

Thanks
/sven
svens
Member
Member
 
Posts: 2
Joined: February 15th, 2009, 12:31 am

Re: TPrintPreview: custom form management

Postby Kambiz » February 15th, 2009, 9:49 pm

I guess you don't create the component (previewtest is nil).

Instead of

Code: Select all
var
  previewtest : TPrintPreview;
begin
    previewtest.AddNewForm('my_test', 10, 10);
...

Drop the component on your form and then call

Code: Select all
begin
  PrintPreview1.AddNewForm('my_test', 10, 10);
...
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests

cron