Convert DOS .PAS program file to Delphi 7 console app without a unit? - delphi

I have an older DOS BP7 app with several program .pas files that are built. In Delphi it looks like I have to create a project to compile a .pas file, however it appears Delphi creates the program in the project file itself and references the .pas file that contains the older program and wants it to be a unit.
It looks like what I'd have to do is convert every .pas file to be a unit, copy over the begin / end from the .pas and place it in the .dpr file or make the program entry point a function or procedure and call that from the .dpr file?
Is there a more direct way to do this so that the .pas file doesn't need to be modified from a program to a unit and so I don't have to create a project for every program?

Related

Delphi open all Files in Project Manager at once

When the IDE starts it normally opens the main form while all other .pas files can be openend through the project manager. I want to load alle those files at once. Is there any way to open all .pas files shown in the project manager at once?
If so can I automate this to get this done each time I open a (specific) project?
This would speed up working on large projects, where you normally have to click on each .pas file to load it into the main editor.
Of course I could simply write a batch to start each .pas in the project directory, but is there a more elegant way to get this done by the IDE itself?
Maybe there's a way to start this batch after the IDE starts up using some extra lines in the .dproj or .dpr or something?

change exe file name and output path

Can I change the name of the compiled exe file and the output folder by Delphi source code. I know I can change that by editing of the "project Settings" by hand.
I want to compile dunit testcases and whenever i use the GUItestrunner, I prefer a different outputfolder and exe file Name
{$ifdef guitestrunner}
CONST
exename = ......
exeoutfolder = ....
{$else}
....
{$ifend}
If i can get a solution for this problem. Any chance to create/compile both executables with ONE mouse click ?
Can I change the name of the compiled exe file and the output folder by Delphi source code.
No you cannot. The output file name is determined by the name of the .dpr file.
Some options:
Use one .dpr file, but use conditional compilation to produce the different variants of the project. Then have a post-build action that copies and renames the output file.
Use one .dpr file for each variant of the project. With this latter approach you can have multiple projects contained in a single project group and then compile all projects in the group with a single IDE action.
My final piece of advice though is to learn how to script your builds. That will free you from the constraints of the IDE. You'll be able to automate repeatable build procedures and avoid the human mistakes that are made when operating a UI to perform repetitive tasks.

XML Parse Error while opening pas file in Delphi XE4 IDE

While double clicking the pas file to open it in Delphi XE4 IDE, I am getting this error:
XML Parse Error:
Reason: The system cannot locate the object specified
This file uses xmldom, XMLIntf, oxmldom, XMLDoc units in its uses clause. I have changed nothing in this file and this opens up with no error in Delphi 7, but in Delphi XE4, its throwing above error when I double click .pas file to open it in IDE. After pressing OK, the .dfm file opens up.
Opening the .pas and .dfm files does not involve XML parsing. The fact that your unit uses some XML related units also does not involve parsing of XML at unit load time.
So this sounds like the IDE has a problem opening some auxiliary file associated with the source file. And something about this file or its reference in the source has not survived the transition from XE4. Look for files with the same stem as the troublesome source unit, but a different extension. Or look for IDE generated {...} comments in the source unit that refer to auxiliary files. This should hopefully lead you to a solution.

Replace RIDL file and typelib in Delphi XE3

I wrote a test project which exposes a COM factory and object. Having tested and found our implementation to be working - i now want to move the code + typelibrary into our main project.
I copied the RIDL + TLB file into the main-project folder. I renamed both files accordingly (to the main project name). I also deleted the project resource file just in case Delphi places the TLB data here. And naturally i deleted the old TLB and RIDL files (I also deleted all DCU files, just in case). Last, I added the RIDL file to the main project and compiled.
The RIDL file is picked up by Delphi during compilation, it generates the TLB file as expected, but somehow it doesnt inject the TLB data into the exefile. So when i start the application i simply get an error message "Unable to load typelibrary". In my code i automatically create the COM factory on startup and update the windows registry. On shutdown the reverse happens.
Having fiddled with the typelibrary editor for hours, trying to register the typelibrary/exe from both Delphi and shell/regsvr32, delphi for some magical reason picked up the new file and everything worked as expected.
Problem is, I have no idea "why" it didnt work to begin with, nor do i know why it worked after hours of trying different combinations. So I am unable to reproduce the success. When updating our codebase I had to do the same on another computer/revision -- but this time it refused to work.
How can I force Delphi to inject the typelibrary?
Is there some "trick" (except the obvious like refreshing the RIDL, which generates the unit correctly but doesnt do anything about the TLB resource problem).
As I understand it the steps are as follows:
Add the .ridl file to the project. This will result in the build process compiling it to a .tlb file.
Link the .tlb resource with a $R conditional directive like this: {$R MyProject.tlb}

How To Import exe file into resources Extract exe from resources and then shell

i want to import exe file into my delphi application resources.
and then extract and run the exe.
my qustion is:
how can i:
Import exe file into my resources
Extract exe file into "c:\" (with SaveToFile function)
Run (Shell exeFilePath) the exe.
See this answer for an example how to include an file as a resource to your app. The example there is for a text file but it is the same idea for the exe file. It also shows you how to load that resource into an TResourceStream and then you just use it's SaveToFile method to save the exe to the disc. Once you have the exe on the disc you can run it with ie CreateProcess.
there are component libraries allow you tou store your file on the from, inside DFMs
For example if installed JediVCL you can drop the TJvDataEmbedded component onto the TDataModule or TForm and load a file into it. Then in the runtime you can extract that file onto disk or into TMemoryStream.
About running - the most simple thing would be to call ShellExecute function - read your Delphi help about it. Or you can use the class from Jedi CodeLib which allow you a lot of customizations. But you probably do not need it.

Resources