Questions tagged [delphi-units]

Delphi units are source code modules (text files with .pas extension) that are compiled individually to form an application.

Delphi units are source code modules (text files with .pas extension) that are compiled individually to form an application. They are composed of four mandatory sections: header, interface, implementation, and closure; and by another two optional sections: initialization and finalization.

Example of the syntax of a unit:

unit UnitName; // Header section (mandatory)

interface // Interface section (mandatory)    
// Used to define required other units, constants, types, global variables, methods

implementation // Implementation section (mandatory)
// Implementation of the declared procedures and functions (methods)

initialization // Initialization section (optional)
// Sentences to be executed the first time that unit is referenced

finalization // Finalization section (optional)
// Sentences to cleanup allocated memory or freeing locked resources

end. // Closure section (mandatory)
29 questions
17
votes
6 answers

Any tool to suggest unit reference automatically for Delphi 2010?

MS Visual Studio has a great feature: it automatically suggests the units to add in using clause when you typing the code with refrences to absent standard classes. Is there any 3-rd party tool to implement similar feature for Delphi? I'm tired to…
Andrew
  • 3,696
  • 3
  • 40
  • 71
14
votes
7 answers

Delphi XE - F1027 Unit not found: 'System.pas' or binary equivalents (.dcu) upon Activation of trial version

I just purchased the full version of Delphi XE Architect after using the trial version for 30 days. I can't build anything, every time I go to build a project I get the error. [DCC Fatal Error] MegaMainPrj.dpr(1): F1027 Unit not found: 'System.pas'…
Daisetsu
  • 4,846
  • 11
  • 50
  • 70
13
votes
14 answers

Why are my units "compiled with a different version" of my own files?

I'm building a program that uses plugins. Unfortunately, the plugin framework's dynamic linking forces the RTL and VCL out of my project EXE and into the BPL versions, and they don't have debug info enabled. So I built a testing framework that…
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
10
votes
4 answers

Is it a good idea to use initialization sections for module registration?

I am looking for a good solution for a decentralized module registration. I do not want a single unit that uses all module units of the project, but I would rather like to let the module units register themselves. The only solution I can think of is…
Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
10
votes
2 answers

How to run procedure from another unit?

Well this kind of n00b question but I still can't figure it out. I have unit main with procedure Discard() in it. Now I have another unit engine and I want to run from it procedure Discard() of unit main. I have main in uses section of engine.pas.…
Vlad
  • 337
  • 1
  • 7
  • 12
9
votes
1 answer

Can I define conditionals in a unit and use them in other units?

I am working on a large unit, the unit got so large that I decided to split it into 3 units. Let's say these unit names are Main, Common, and Objects. The Main unit uses both the other two units, and the Objects unit also uses the Common unit. There…
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
9
votes
3 answers

How to recompile a specific unit from the VCL?

I want to apply a fix from QC to a Delphi 2009 unit (DBClient as it happens). I know I need to copy the unit to another directory and make the change to the copy. How do I then get Delphi to compile that unit and use it in favour of the DCU that…
Rob McDonell
  • 1,309
  • 9
  • 15
7
votes
5 answers

Does it make a difference if I clean up my uses clause if the removed units are still used in other units?

Personally I like it if my uses clauses are as small as possible, but in many applications the really big units (in terms of bloating the executable) like Forms or VirtualTrees are needed in at least another unit anyway. So: Does it make a…
Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
4
votes
1 answer

Check at compile time if a unit exists

I want to use a unit if it exists. Is there something like {$IF Declared(MyUnit)} for units, or a different way? I installed a demo version of a component package, and would like to conditionally use units from it, and conditionally add menu items…
Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
4
votes
4 answers

Access main form from child unit in Delphi

I want to access a main form variable from a class that is called from the main from. Something like this: Unit1: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,Unit2,…
TreantBG
  • 1,192
  • 6
  • 25
  • 44
3
votes
1 answer

Open File at Cursor Does Not Open the File in the IDE

When I mouse over the UnitNames within the Uses clause a window pops up showing the UnitName Namespace. For example when I mouseover the SysUtils unit I see SysUtils Namspace in a popup window. If I right-click on SysUtils and choose Open File at…
2
votes
3 answers

"Duplicate" units in Delphi by name, referenced by components, problem with compile

We are using several component packages by different vendors, and two of them both have a "regexp.pas" unit available inside their directory structure. Problem now is that regardless of the order we compile them in, one of them complains about the…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
2
votes
8 answers

Defining types from other units in Delphi

Var A : Array [1..4] of Integer; B : Array [1..4] of Integer; Begin A := B; Won't work as loren-pechtel said here the problem is A and B for me are in different units. So, is there a way to define a type definition from a existing…
Arthur
  • 3,376
  • 11
  • 43
  • 70
2
votes
4 answers

How to use Unit files in Delphi

I'm just trying to get the hang of separate units to make my code more encapsulated. I'm trying to get the public/private declarations of my methods sorted out, so I can call them from other units that use testunit. In this example I want to make…
Arthur
  • 3,376
  • 11
  • 43
  • 70
2
votes
3 answers

F2051 Unit was compiled with a different version (again)

(Warning: long read. This question references a lof of the other questions about F2051) We have a folder named PatchLibs in our source tree in which we put modified files of third party sources. This is in the project search path:…
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
1
2