[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Checking for existance of an activex control

Posted on 2005-04-28
5
Medium Priority
?
189 Views
Last Modified: 2012-05-05
I've got an app that has a reealplayer activex control in it.  If the user doesnt have realplayer, it errors out horribly.  How can I gracefully check for the control in the registry and exit if its not there?

0
Comment
Question by:hibbidiji
  • 3
  • 2
5 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 1000 total points
ID: 13890761

If you have placed the AX control on one of your forms, then Delphi will attempt to instantiate the control when the form is created. If this is the case, then you should be handling the check in the project source. An example of handling this (displays a message) is shown below. You may need to double check the CLSID for the control, as I got it from a google search (check the type library pas file), but the rest of the code is valid for the handling.

Regards,
Russell

----

program Project1;

uses
  Windows,
  Forms,
  ActiveX,
  ComObj,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

// Real player CLSID - check your type library for the real player control to
// ensure this CLSID is correct
const
  CLASS_RealPlayer:    TGUID = '{CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA}';

var
  pvUnk:      IUnknown;

begin

  Application.Initialize;

  // Attempt to create an instance of the real player
  if (CoCreateInstance(CLASS_RealPlayer, nil, CLSCTX_ALL, IUnknown, pvUnk) = S_OK) then
  begin
     // Release the interface
     pvUnk:=nil;
     // Allow application to continue
     Application.CreateForm(TForm1, Form1);
     Application.Run;
  end
  else
    // Not installed, or missing components
     MessageBox(0, 'Please install the Real Player ActiveX control', nil, MB_OK);

end.
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 13890875
Perfect code that worked first try!

Thanks!
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 13890935

You are very welcome (and don't forget to close this question out ;-)

Regards,
Russell
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 13891786
Oops! you'd think after dozens of questions I'd remember.  I think the working first try code had me so excited I forgot :)   (I tend to get a lot of code with missing pieces)

Thanks again
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 13891820
Again, very welcome. I completely understand too, which is why I try to "get it all there" the first time around...  less aggravation for all involved. <g>

Happy coding,
Russell

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

864 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