IDE

IDE

How to detect if running in Delphi IDE
Commenting out large sections of code
Duplicate resource identifier error
2% resources, in design mode
Disk full error
Runs in IDE


How to detect if running in Delphi IDE

Question


How to detect if your program running in Delphi IDE or running as a standalone

EXE?

Answer


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 }


Commenting out large sections of code

Question


While we're on this kind of thing, has anyone got a quick way of commenting

out a highlighted block of code lines??

It must work correctly with pre-existing embedded comments in {braces}.

Otherwise it's back to the Windows recorder!

Answer


A:

There are 2 sets of comment characters in pascal, {} and (* *). You can

embed one sort in the other.

Hence putting a (* at the start of your block and a *) at then end would

still work with embedded { } comments.


Duplicate resource identifier error

Question


Duplicate Resource identifier (c:/delphi/lib/controls.res)  ERROR!

I keep getting this... I don't know what's wrong... my project .RES

called (project1.res) doesn't have a single thing that's in common

with controls.res!

This is driving me absolutely nuts... the only thing I ever did was

to delete {$R .res} in the project file but since the, I've replaced

that line...

Answer


A:

Do you have the VCL source?  If so, you may want to recompile the whole thing

by adding that directory to your Library path in Environment Options | Library.

I think I had to do this once to get rid of such an error.  Another thing to

do is to figure out which $R directive is causing the problem, by removing it

temporarily and recompiling.  You can temporarily disable the $R directive by

adding a '.' before the $ (that's one of many ways to do it).



A:

You probably have subclassed one of the built in VCL's.  You need to be sure

that the resource identifier for your icon is unique.  Just pull it up in any

resource editor and change its number. Then you should be able to rebuild your

library.


2% resources, in design mode

Question


I have a problem with Delphi. When I load Delphi my resources drop from

around the 65% mark to around the 45% mark. No real problem there

but..... When I load my project it suddenly drops to around the 2%

mark!! :(

The project is not that complex, about 5 screens one Tabbed notebook on

each with about 20 controls on each page. No database stuff yet. A few

speed buttons with glyphs on each screen. Nothing exciting.

The question is, where are all my resources going and what can be done

about it? When you run the exe of the app it uses only the customary

15%.

Answer


If you have all of the forms open (either displayed or minimized) and

all of the units open in the editor, then resources very quickly

disappear. Try closing all forms and units, and only have open those

ones that you will be using. It is when the resources are used like

this that compiles start to hang Delphi and the machine.


Disk full error

Question


I keep on getting disk full errors when I try to recompile my component

library. I have over 150MB of disk space free and 32MB of ram. The

problem only started after I created a few .DCR files (the bitmaps in

the component palette) for some components.

Answer


A:

Try deleting everything in your project except the dpr, pas and dfm files

and recompile. It sounds like one of your project files has been corrupted.

I had a similar occurence once and fixed it that way.


Runs in IDE

Question


How can I detect whether the application runs in the IDE or as

a compiled program without the active IDE?

Answer


  Here are three routines which all work for D1 on Win 3.1x.



 function LaunchedFromDelphiIDE: Boolean;

{----------------------------------------------------------------}

{ Checks whether the calling application was launched from the   }

{ Delphi IDE.  From a posting to Delphi-Talk by Ed Salgado       }

{  of Eminent Domain Software.                }

{----------------------------------------------------------------}

 begin

   LaunchedFromDelphiIDE := Bool(PrefixSeg) {i.e. not a DLL} and

                            Bool(PWordArray(MemL[DSeg:36])^[8]);

 end; {LaunchedFromDelphiIDE}





 function DelphiLoaded: Boolean;

{----------------------------------------------------------------}

{ Checks whether Delphi is loaded.  Gives correct result         }

{  - whether calling App is launched free-standing or from IDE   }

{  - whether or not Delphi has a project open                    }

{  - whether or not Delphi is minimized.                         }

{ From ideas by Wade Tatman (wtatman@onramp.net).                }

{----------------------------------------------------------------}

 begin

   DelphiLoaded := false;

   if WindowExists('TPropertyInspector', 'Object Inspector') then

    if WindowExists('TMenuBuilder',      'Menu Designer') then

     if WindowExists('TAppBuilder',      '(AnyName)') then

      if WindowExists('TApplication',    'Delphi') then

       if WindowExists('TAlignPalette',  'Align') then

        DelphiLoaded := true;

 end; {DelphiLoaded}





 function DelphiInstalled: Boolean;

{----------------------------------------------------------------}

{ Checks whether Delphi is installed by looking for Delphi.ini,  }

{ then Component library in directory pointed to by ini file.    }

{----------------------------------------------------------------}

 var

   IniFile: string;

 begin

   DelphiInstalled := false;

   IniFile := WindowsDirectory + '\Delphi.ini';

   if FileExists(IniFile) then

     if FileExists(GetIni(IniFile, 'Library', 'ComponentLibrary'))

       then DelphiInstalled := true;

 end; {DelphiInstalled}





  I'm sure one of the above will help.  The last two routines

  use some other encapsulations of Windows API rouines or of

  Delphi classes and they are defined as follows:





 function WindowExists (WindowClass, WindowName: string): Boolean;

{----------------------------------------------------------------}

{ Checks for existence of specified Window using Pascal strings. }

{ To search on WindowName only, use WindowClass of '(AnyClass)'; }

{ to search on WindowClass only, use WindowName of '(AnyName)'.  }

{----------------------------------------------------------------}

 var

   PWindowClass, PWindowName: PChar;

   AWindowClass, AWindowName: array[0..63] of Char;

 begin

   if WindowClass = '(AnyClass)' then

     PWindowClass := nil         else

     PWindowClass := StrPCopy(PChar(@AWindowClass), WindowClass);



   if WindowName  = '(AnyName)' then

     PWindowName := nil         else

     PWindowName := StrPCopy(PChar(@AWindowName), WindowName);



   if FindWindow(PWindowClass, PWindowName) <> 0 then

     WindowExists := true                        else

     WindowExists := false;

 end; {WindowExists}





 function WindowsDirectory: string;

{----------------------------------------------------------------}

{ Returns path of Windows directory (without trailing backslash) }

{----------------------------------------------------------------}

 const

   BufferSize = 144;

 var

   ABuffer: array[0..BufferSize] of Char;

 begin

   if GetWindowsDirectory(PChar(@ABuffer), BufferSize) = 0

     then WindowsDirectory := ''

     else WindowsDirectory := StrPas(PChar(@ABuffer));

 end; {WindowsDirectory}





 function GetIni (const IniFile, Section, Entry: string): string;

{----------------------------------------------------------------}

{ Gets an initialisation 'profile' string from the specified     }

{ Entry in the specified [Section] of the specified INI file     }

{ (adding the '.ini' if not supplied).  Returns a null string    }

{ if the IniFile, Section or Entry are not found.                }

{----------------------------------------------------------------}

 var

   IniFileVar: string;

   IniFileObj: TIniFile;

 begin

   if StrEndsWith(IniFile, '.ini') then

     IniFileVar := IniFile

   else

     IniFileVar := IniFile + '.ini';

   IniFileObj := TIniFile.Create(IniFileVar);

   GetIni := IniFileObj.ReadString(Section, Entry, '');

   IniFileObj.Free;

 end; {GetIni}


Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > delphi > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction