?
Solved

How do I disable File | Print menu item when no default

Posted on 1998-10-09
6
Medium Priority
?
163 Views
Last Modified: 2010-04-06
How do I disable File | Print, The print menuitem and printer setup menuitem when no default printer is installed.
0
Comment
Question by:TCSCode
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 1

Accepted Solution

by:
ow earned 240 total points
ID: 1342398
Hi TCSCode,

look at the Registry and disable the MenuItem:

  var
    Registry :tRegistry;
    Print1 :tMenuItem;
    Key :string;
    EnablePrint :boolean;
.
  Registry := tRegistry.Create;
  Registry.RootKey := HKEY_CURRENT_CONFIG;
  Key := '\System\CurrentControlSet\Control\Print\Printers';
  EnablePrint := FALSE;
  if Registry.OpenKey(Key, FALSE) then
    EnablePrint := (Length(Registry.ReadString('Default')) = 0);
  Print1.Enabled := EnablePrint;
  Registry.Free;
.

regards
  ow
0
 

Author Comment

by:TCSCode
ID: 1342399
Hello Ow.
      For some reason I cannot get this code to work for 1 basic reason, I am not good with TRegistry, I tryied the code many different ways and all I come up with is Access violation Errors.
Could you make me a demo showing me where i should put this code.
                                                 Thanks TcsCode.
0
 
LVL 1

Expert Comment

by:ow
ID: 1342400
Hi TCSCode,

when you insert a menu in a form, the form will contain some fields of type "tMenuItem", one of them should be for printing, normaly "Print1 :tMenuItem".
Check for a default printer in tForm.Create:


unit Unit1;

INTERFACE

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry, Menus;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Print1: TMenuItem;
    PrinterSetup1: TMenuItem;
    Quit1: TMenuItem;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    end;

var
  Form1: TForm1;

IMPLEMENTATION

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
  var
    Registry :tRegistry;
    Key :string;
    EnablePrint :boolean;
  begin
  Registry := tRegistry.Create;
  Registry.RootKey := HKEY_CURRENT_CONFIG;
  Key := '\System\CurrentControlSet\Control\Print\Printers';
  EnablePrint := FALSE;
  if Registry.OpenKey(Key, FALSE) then
    begin
    TRY
      EnablePrint := (Length(Registry.ReadString('Default')) > 0);
    EXCEPT
      EnablePrint := FALSE;
      end;
    end;
  Print1.Enabled := EnablePrint;
  end;

initialization
end.


regards
  ow
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:TCSCode
ID: 1342401
I just have one last question. What is the initialization for in unit1? and Thanxs Ow..
0
 
LVL 1

Expert Comment

by:ow
ID: 1342402
Hi TCSCode,

well, in fact I write "initialization" in a unit even if there is no init code, cause I like it complete and I don't like single ends. But it's not absolutly necessary.

regards
  ow

0
 

Author Comment

by:TCSCode
ID: 1342403
Hi Ow.
 
Complete end, What good does adding "initialization"??? Thanks TCSCode.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question