How to compile and run this Delphi code without installing an IDE?

They say to create winform:

var F : TForm; L : TLabel; begin F := TForm.Create(Application); L := TLabel.Create(F); L.Parent := F; // Needed to have it show up on the form. L.Left := 50; L.Top := 50; L.Caption := 'This is an example'; F.Show; end; 

This is actually from my previous question .

If it is a C program, I can run it as follows:

 > gcc foo.c -o foo.exe > foo.exe 

How can I do this similarly in Delphi?

+3
source share
3 answers

To compile Delphi code, you need a compiler. There are no free versions in Delphi, so if you do not find the old one, you will have to buy Delphi. Delphi comes with a command line compiler like gcc, and can compile programs without an IDE.

Delphi 2006 and before win32:

 dcc32 YourProject.dpr 

Delphi 2006 and before .Net:

 dccil YourProject.dpr 

Delphi 2007 and after:

 msbuild YourProject.dproj 

This will result in a compiled binary, and in the case of an EXE, you can run it the way you used to.

There are free Delphi alternatives such as FreePascal and their free Lazarus IDE. I have not tested myself, but I am sure that it comes with a command line compiler.

+9
source

You must write this code in a DPR file. The general structure of the DPR file looks something like this:

 program {ProgramName}; uses {List of used units}; begin {Your code} end. 

So, for the above code, your DPR file will look like this:

 program Project1; uses Forms, StdCtrls; var F : TForm; L : TLabel; begin F := TForm.Create(nil); try L := TLabel.Create(F); L.Parent := F; // Needed to have it show up on the form. L.Left := 50; L.Top := 50; L.Caption := 'This is an example'; F.ShowModal; finally F.Free; end; end. 

You can enter this code into a text editor and save it as Project1.dpr.

Now you can use the Delphi command line compiler to compile it:

dcc32.exe Project1.dpr

+2
source

Much easier, just

 dcc32 "name of the project" 

Even if the program exists of 10 units, the compiler will autorevolve it if it is in the current search path of the object (see dcc32.cfg or add dirs with -U and -I). Please note that some of the β€œfree” versions of Delphi Explorer do not ship with the cmdline compiler.

For .NET, this is dccil.

Of course, if you compare with gcc, Free Pascal / Lazarus is a more logical choice (but not for .NET).

+1
source

All Articles