0
votes

Been looking for the best way to do this now for some time but no answers.

I'm using Windows XP and Delphi 6.

I have basically 2 applications which I want identical source code for. The only difference is that the 2 application look at different SQL servers for their data. The SQL server is specified in an .ini file that the Delphi reads on start-up.

My problem is that I would like to be able to switch from one application to the other from within the application itself (application 1 switches to application 2).

I know I can rename the application before compiling but I need the source code the same. I also can not rename the .exe file after compiling as the .ini file looks at this .exe name when running. I have tried to read the application name from the .ini file but again this does not work.

Any help would be great.

3
I would register a custom message which I would then broadcast and on its handler I would bring the instance to front, but what if there'll be e.g. three instances of the application ?TLama
If *the only difference' is that they look at different SQL servers why not just have one app that shuts down operations and the connection to Server1 and then opens the connection to Server2 and restarts operations? And have two INI sections [Server1] and [Server2].Jan Doggen
Identical source code...two applications, two servers? I see no reason whatsoever that this can't just be one application.J...
The application is linked to a production lines (1 and 2). A user must be able to go to his station (one of 4) and select which line he is going to control. When he selects a line it will connect to that lines database (Line 1 or Line 2) for him to make changes. These changes are then used by a different application to act on these changes. I could change the code and combine into a single application but this would take quite some time as there is many thousands of lines of code to sort and test.Jon Waterhouse
If all that is changing is the database the application is pointing to, I can't understand how it can be that big of a change to make. One menu item - select Line 1, select Line 2. Close one session, open the other... the rest remains the same.J...

3 Answers

5
votes

There should be one application only, that switches behaviour at runtime.

I would extend the application to allow the .ini file settings to be overridden by command line arguments. If no arguments are specified, the values are taken from the .ini file. If arguments are specified then they take precedence over the .ini file.

0
votes

If you absolutely have to stick with having two separate applications, there is one simple solution.

Create two separate folders, let's say APP1 and APP2 then copy all application files (EXE, INI and everything else that your application requires) to both folders. Change INI file of APP1 to point to Server1 and INI file of APP2 to point to Server2.

This solution assumes that the INI file is somewhere in application's folder structure and your application is set to read it from there. If that is the case, then nothing else has to be changed. Using this method will even allow you to have multiple applications running at the same time.

0
votes

Here are two suggestions

A. Create an MDI application. See delphi example called MDIApp.dpr.

Your ChildMDI Windows will be the code for each line. When you create the MDIchild window read the appropiate .ini file to initialize the MDICHild window. This assumes you will have a master MDIApp.ini which tells you how many lines you have and in there define where where to fetch the .ini files for each line. So in your .ini file if you say your have 2 lines you would say

Lines=2
;Then have an iterator to read the paths/parameters of the .ini file 
; to initialize Line Window
IniFilePathForLine1=
IniFilePathForLine2=

Use the Child Ini Files to initialize the MDIchild windows

B. Read the Processes Running and bring it to front

The problem I see with what you have described is that all lines will have all processes/applications running. i.e. Line1 will be running application for Line1 and Line2. Two applications per terminal. I am assuming these apps are just for display and configuration and the real work is done in a single application elsewhere.

Read the tasks/Processes running on the terminal using something like.

How to get applications from Windows Task manager (Applications Tab) + their locations on HDD from Delphi

Filter what is displayed on the screen so only your applications show up Then bring it to the front

How to bring my application to the front?