Solved

Detecting if program running from within Delphi IDE ? Component shareware!

Posted on 1998-11-19
12
520 Views
Last Modified: 2010-04-04
I've created a component that I want to make available as shareware.
I want to be able to detect (As many other shareware components do) if the program using my component, is running from within delphi, or if it is the .exe file that is running on its own, ie not from within delphi?

Ie no registration message displayed while running from within delphi IDE.
When then run in an *.exe, wihtout Delphi IDE, then must not be functional anymore, and display a message saying that this version is unregistered, and needs to be registered first.

How do I test for this from within my component.
My component must be fully functional at 'design time', and when run from within delphi, but not when the compiled *.exe containing the component is run on its own.
Thanks in advance
Adrian
0
Comment
Question by:doogie
  • 4
  • 4
  • 4
12 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 350 total points
ID: 1347347
Hi doogie,

lots of possibilities, here are some :

A: function DelphiLoaded : boolean;
{----------------------------------------------------------------}
{ Checks whether Delphi is loaded.  Gives correct result whether }
{ or not Delphi is minimized and whether or not Delphi has a     }
{ project open.  Also gives correct result whether the calling   }
{ application is launched free-standing or from within the IDE.  }
{ From ideas in a posting to the Delphi-Talk List by Wade Tatman }
{ (wtatman@onramp.net).       Mike O'Hanlon, The Pascal Factory. }
{----------------------------------------------------------------}
   function WindowExists(ClassName, WindowName: string): boolean;
   {------------------------------------------------------}
   { Checks for the existence of the specified Window,    }
   { conveniently using Pascal strings instead of PChars. }
   {------------------------------------------------------}    var
     PClassName, PWindowName: PChar;
     AClassName, AWindowName: array[0..63] of char;   begin    if ClassName = '' then PClassName := nil
     else PClassName := StrPCopy(@AClassName[0], ClassName);
if WindowName = '' then PWindowName := nil
     else PWindowName := StrPCopy(@AWindowName[0], WindowName);
if FindWindow(PClassName, PWindowName) <> 0 then WindowExists := true
     else WindowExists := false;  
end;  

{WindowExists}

begin {DelphiLoaded}
  DelphiLoaded := false;
  if WindowExists('TPropertyInspector', 'Object Inspector') then
    if WindowExists('TMenuBuilder',     'Menu Designer') then
      if WindowExists('TApplication',   'Delphi')    then
        if WindowExists('TAlignPalette','Align') then
          if WindowExists('TAppBuilder','')  then
            DelphiLoaded := true;
end;

{DelphiLoaded}

A:

The following routine will return TRUE when running in the Delphi IDE (NOTE:  this does _not_ work if this routine is in a DLL).

function InIDE: Boolean;
begin  
Result := Bool(PrefixSeg) and
 Bool(PWordArray(MemL[DSeg:36])^[8]));
end;  { InIDE }

A:

Function IsDelphiLoaded: Boolean;
begin
 Result := FindWindow('TAppBuilder',Nil) > 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if IsDelphiLoaded then
  MessageBox(handle,'IDE is running','Important',IDOK) else
  MessageBox(handle,'IDE is NOT running','Important',IDOK);
end;


or

if csDesigning in ComponentState then ...

Regards, Zif.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1347348
doogie,

I would suggest something like this:

Use "csDesigning in ComponentState" to check in your components create function, if your component is created at designtime or runtime. If it is created at designtime, write a key value to the registry (perhaps a encrypted harddisk serialnumber or something like this). Now if your create function is called at runtime you have to check, whether a valid key value is found in the registry. If not, open an infobox and close the program.

The result of this solution would be that a program that uses your component will run on the computer where it was designed (regardless whether Delphi IDE is currently running or not), but not at all on any other computer.

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1347349
Biggest advantage: This solution is totally independent from the delphi version. It will work with every past and future version of delphi.
0
 

Author Comment

by:doogie
ID: 1347350
Zifnab ... will this work with Delphi 2,3,4.

I suspect that they might require different solutions.
I need to be able to check for all above versions.

I'll accept your answer if this is so

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347351
or

    if csDesigning in ComponentState then ...

should work in all versions.

The other I don't know if they work in higher versions. You've to test this yourself.

Zif.
0
 

Author Comment

by:doogie
ID: 1347352
ZifNab
if csDesigning in ComponentState then... works to detect if component specific states are allowed at design time, but as soon as you run the application from within IDE, then if csDesigning in ComponentState returns false, thus not what I need. It should only return false if not running in IDE.

In your one answer the Prefixseg, and MemL are undefined ... can you explain how to use these?

The first answer you gave works, except that for delphi 4 you have to replace .. if WindowExists('TApplication',   'Delphi')    then .. with if WindowExists('TApplication',   'Delphi 4')    then ..
I haven't tested for delphi 2,3 yet, but I hope that it just requires 'Delphi 2' or 'Delphi 3'. .. could place them as OR statements together.


0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 20

Expert Comment

by:Madshi
ID: 1347353
Seems that my comment has been ignored...   :-(
0
 

Author Comment

by:doogie
ID: 1347354
No didn't ignore your suggestion ... not entirely in line with what I want. No registry writes!! most programmers don't want components with this behaviour, and quite easy to trick the PC then.
PS If IDE not running, then must not be available!
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1347355
ok, no problem...
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347356
doogie, I'm afraid that PrefixSeg and MemL only exist at D1. So you can't use this method. Sorry.
0
 

Author Comment

by:doogie
ID: 1347357
Thanks chaps ... still do some digging till I'm happy with the result. You answered the question, the points are yours.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347358
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now