TPrintPreview: custom form management

Post here your experiences, comments, suggestions, or bug reports regarding to the DELPHI AREA products. Not-matching topics will be moved or deleted.

TPrintPreview: custom form management

by svens » 15/02/09 13:01

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: 15/02/09 00:31

Re: TPrintPreview: custom form management

by Kambiz » 15/02/09 15:49

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

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1688
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: TPrintPreview: custom form management

by Kambiz » 15/02/09 16:04

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

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1688
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: TPrintPreview: custom form management

by svens » 15/02/09 16:20

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: 15/02/09 00:31

Re: TPrintPreview: custom form management

by Kambiz » 15/02/09 21:49

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

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1688
Joined: 07/03/03 19:10
Location: Tehran, Iran


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest