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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 581
  • Last Modified:

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

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
doogie
Asked:
doogie
  • 4
  • 4
  • 4
1 Solution
 
ZifNabCommented:
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
 
MadshiCommented:
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
 
MadshiCommented:
Biggest advantage: This solution is totally independent from the delphi version. It will work with every past and future version of delphi.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
doogieAuthor Commented:
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
 
ZifNabCommented:
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
 
doogieAuthor Commented:
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
 
MadshiCommented:
Seems that my comment has been ignored...   :-(
0
 
doogieAuthor Commented:
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
 
MadshiCommented:
ok, no problem...
0
 
ZifNabCommented:
doogie, I'm afraid that PrefixSeg and MemL only exist at D1. So you can't use this method. Sorry.
0
 
doogieAuthor Commented:
Thanks chaps ... still do some digging till I'm happy with the result. You answered the question, the points are yours.
0
 
ZifNabCommented:
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now