Delphi Programming Interview Questions and Answers -Top Answers to Delphi Interview Questions. Learn Delphi programming language with simple and easy examples.
Embarcadero Delphi is an integrated development environment (IDE) for desktop, mobile, web, and console applications. It’s also an event driven language. Delphi's compilers use their own Object Pascal dialect of Pascal and generate native code for several platforms: Windows (x86 and x64), OS X (32-bit only), iOS (32 and 64-bit), Android and Linux (64-bit Intel).Currently Embarcadero Delphi, known formerly as CodeGear Delphi & Borland Delphi (1995–2008), is an IDE for Microsoft Windows based application development.
Embarcadero Delphi 10.2 Tokyo, on March 22, 2017 Embarcadero released RAD Studio 10.2 Tokyo, adding 64-bit Linux support, limited to console and non-visual applications. In addition this release features RTL and IDE improvements, multi-tenancy support in RAD server and improved database capabilities. Current version of Delphi 10.2.1 Tokyo / August 8, 2017.
What is Delphi?
The origins of the Delphi programming language stem from an extension of the Pascal programming language, which was designed for use in the object-oriented programming arena, called Object Pascal. Delphi is the choice for developers wanting the power, readability and flexibility of the Modern Object Pascal language, coupled with native compilers and component libraries for fast single source code development on Windows, macOS, iOS, Android and Linux.(Or)A Rapid Application Development (RAD) system developed by Borland International, Inc. Delphi is similar to Visual Basic from Microsoft, but whereas Visual Basic is based on the BASIC programming language, Delphi is based on Pascal. This feature was adopted and further developed into the Object Pascal language, an object-oriented programming language which allows for intuitive data modeling, data integrity, and reusability across distributed systems.

What is New in Delphi 10.2.2?
Delphi 10.2 added a 64-bit Linux compiler, improved IDE menus for faster navigation, and multi-tenancy support in RAD Server. Now Delphi 10.2.2 adds new features including FireMonkey Quick Edit support, a number of new VCL controls, a new dark themed IDE option, a RAD Server single site deployment license (Enterprise/Architect Editions), installer and welcome page enhancements.

What are the advantages of Delphi?
In the early days in college, there are basic programming courses and  programming language used was Pascal, so from then on was known programming pascal.
  •  A very clear syntax, leading to readable code.
  • Some of the coursework must create a program with a good interface, because the basic know pascal the first "forced" to make with Delphi.
  • In terms of ease of interface, no doubt. Especially the early 2001's interface (GUI) it's easier than VB Delphi let alone VC++ .
  • A then-revolutionary IDE which allowed to implement GUIs by drag & drop, making it easy to draw a nice UI, add event handlers, and test it in real time. It was the closest you could get to the RAD (Rapid Application Development) concept at the time.
  • A structured programming language and syntax are clear, so easy to read, studied and understood
  • The speed of its compilation
  • Support additional component that is very much on the Internet, even for a freeware category with the same quality or better than commercial components
  • Support community on the Internet is very much
How does Delphi handle Windows callbacks?
Just like C: You can get a far pointer to your callback procedure (you have to remember to declare it with the "far" qualifier, unless you have {F$+} in effect to force all calls to be far), pass the pointer to the Windows callback function, and there it is.

How much disk space, memory, etc.? Do I need to run Delphi?
The minimum installation of Delphi takes about 30Mb, and the full install takes 80Mb. In order to run it well, you'll need a 486 with a minimum of 8Mb of RAM, though I personally wouldn't try to run it in less than about 12Mb. I use a 486DX2/66 at home and a Pentium-90 at work, and to be honest, there's not much difference between them--Delphi's compiles are so fast that the CPU is really not a bottleneck.

How is the memory used within an object in Delphi?
Classes are built to create objects and then the objects are allocated in the constructors and used in the methods. The objects that are allocated in the constructor should have a releasing point and that is also in the destructor method. The process in which, the constructor constructs, and after the work destructor destructs is called converse process. The classes can be made to handle the memory properly by using the persistence property after the object that is currently used is being destroyed.
The example is as follows:
unit My;
TMy = class
fileData: TStringList;
Constructor Create (const fileName: string);
Destructor Destroy; override;
procedure PrintFile;

Explain pointers in Delphi? What are the different types of pointers used in Delphi?
Pointer is a variable that holds the address of anything in memory. Pointers are a special type of variable. Like a meta-variable. They can point to other variables, or to memory. You might use a record pointer, for example, to point to a block of memory where you have stored lots of record data. You would then use the pointer just as if it were a record variable. We'll see how below. When calling Windows APIs (Application Programmer Interfaces), we are obliged to use pointers.
Delphi provides a number of typed pointer types, such as PChar, and PExtended, along with a generic, 'point to anything' type - the Pointer type. The nice thing about the typed pointers is that they work sensibly with the Inc and Dec functions. Incrementing a PInt64 pointer will add Size of (Int64) bytes to the pointer address so that it points to the next Int64 variable in memory. The Pointer type is a dangerous one - it falls foul of Delphi's normally tight type handling. Use it with care, or you will end up addressing the wrong memory.

What is NILing pointers?
 NILing pointers: Unassigned pointers are dangerous. Since pointers let us work directly with computer's memory, if we try to (by mistake) write to a protected location in memory we could get a GPF error. This is the reason why we should always initialize a pointer to a special value of NIL. The reserved word nil is a special constant that can be assigned to any pointer. When nil is assigned to a pointer, the pointer doesn’t reference anything. Delphi presents, for example, an empty dynamic array or a long string as a nil pointer.

What is the difference between client-only and client-server packages?
Client-only package can be used in server environment, as long as the server acts as a client, when using the selected protocol. For example, you can use SFTPBlackbox client-only package to transmit the files from your server to some remote server, as long as your server initiates SFTP connection and acts as an SSH/SFTP client.
Certain packages are offered in client-only and client-server variants. These are SSLBlackbox, SSHBlackbox and SFTPBlackbox. Client-only packages include the components, which implement only the client side of the corresponding protocols. Client-server packages include the components suitable for both client-side and server-side of the communication.

What are records in Delphi?
Records are a useful and distinguishing feature of Delphi. They provide a very neat way of having named data structures - groups of data fields. Unlike arrays, a record may contain different types of data. Records are fixed in size - the definition of a record must contain fixed length fields. We are allowed to have strings, but either their length must be specified (for example a: String [20]), or a pointer to the string is stored in the record. In this case, the record cannot be used to write the string to a file. The TPoint type is an example of a record.

What is Enumerations?
The provision of enumerations is a big plus for Delphi. They make for readable and reliable code. An enumeration is simply a fixed range of named values. For example, the Boolean data type is itself an enumeration, with two possible values: True and False. If you try to assign a different value to a Boolean variable, the code will not compile.

What is the difference between Delphi and Delphi Client/Server?
Delphi Client/Server includes everything from Delphi Desktop, plus the following:
  • SQL-Links 2.5, which includes native client drivers for Oracle, Sybase, Informix, and InterBase, and includes full royalty-free redistribution rights to those drivers, and which costs $995 if bought separately;
  • The Local InterBase Deployment Kit, $495
  • ReportSmith/SQL, $300
  • The VCL source code, which is available separately for $100
  • "Team development support" -- interoperation with PVCS (obviously, this is no use to you if you don't own PVCS), not available separately
  • The visual query builder, which creates SQL statements for you, also not available separately
What is object orientation in Delphi?
Object orientation radically changed the face of programming for many people. It took the concept of subroutines into a completely different zone. Now they retained their data, and were in fact, collections of routines under one umbrella. You called an object to do something, and left the object to sort out how it did it. You did not need to furnish the internal data since it was retained across calls. For example, a list object could have items added or removed from the list at will. And the object could be asked to sort the list into sequence. Objects also allowed events, such as mouse clicks, to be handled neatly - a button object could call a routine (method) of another object when clicked. This was now true modularization.
Object Orientation has transformed the process of application development. It has allowed complex code to be written in nicely encapsulated modules (objects). When you create an object, Delphi handles the memory allocation for the object as you call the Create method of the object class. But there is a down side to this automation that is often overlooked, especially by newcomers, giving rise to memory leaks. (Reference Delphi)

What are memory leaks?
 Every time you no longer use an object in your code, you should delete it, thereby freeing the memory it was allocated. If you don't do this, your program can allocate more and more memory as it runs. This failure to discard unwanted blocks of memory is called a memory leak. Run the program long enough and you will use up the memory resources of your PC and the PC will slow down and eventually hang. This is a very real problem in many programs, including commercial applications. If you are serious about your code.

Write a program to show the memory leak?
The program shows the procedure to create one or more objects involved in the operations like:
Procedure PrintFile (const fileName: string);
myFile : Text File;
fileData: TStringList;
i: Integer;
// this creates the TString list to allocate the object memory
fileData: = TStringList.Create;
// This Loads the file contents into the string list and dynamically expand the size //of the object.
fileData.LoadFromFile (fileName);
 This process is being called for the TStringList object that is being created and filled with the contents consists in the file.
The statement needs to be added to free up the memory and release it when the object terminates.
FreeAndNil (fileData); the statement provides a way to call the process as many times as it is required without the memory lea

What is the function of Inheritance in Delphi?
Inheritance is a method to inherit the properties of the parent’s class by the child class.
  • Inheritance is used in Object oriented language and it deals with the real world objects and information.
  • The data in these scenarios is treated as an object and it has the characteristics like size and the actions that are performed on them.
  • In inheritance a class is dependent on another object. The child object inherits the properties of the parent’s class and uses it.
  • Child class has its own features but it also inherits the properties or the features from the parent’s class.
What is RTTI? How does Run-Time Type Information (RTTI) work?
RTTI: Run-time type information (RTTI) is a programming paradigm in which information about a type can be obtained at run time. If RTTI generation is enabled, the resulting binary includes special metadata that contains information about types (for example, class ancestry, declared fields, annotated attributes). Using the functionality provided in the System.Rtti unit, you can obtain this information at run time. The net result is the ability to create more abstract and generalized frameworks that can operate on any type that exposes RTTI.
The operators that is being used for RTTI are “as” and “is”. The operators are needed to have the information at runtime.
 The “as” operator is a protected typecast that allows the compiler to treat one object at a time.
This also allows one type to be changed to another type and it shows an error if the type is not compatible with the system.
The “is” operator allows the user to compare the instances of the object to a class. This is used to test the typecast using “as”.
The example is shown below:
(MyTime is TSport)
(MyTime is TBasketball)
not (MyTime is TFootball)

What is stored in the RTTI?
The RTTI for an object contains quite a few sections:
Automation table
Init/finalization table
Type info table
Virtual Method Table (VMT):
  • Published field table
  • Published method table
  • Dynamic method table
  • Class name
  • Instance size
  • Pointer to its parent class
  • TObject virtual methods
  • User-defined virtual methods
Explain FindFirst, FindNext and FindClose in Delphi?
FindFirst: Find First allows the searching of the first file in the directory that brings out the proper search result. It allows the users to look for specific files and provides lots of wild cards to make the search in a better way. If the file is being found then the search result creates an object keeping the track of the file.
FindNext: Find Next provides the functionality to find the next item in succession of the search criteria. It provides the result to the Find First and if matches it results back with the all the searches that are after one another matching that search criteria.
Findclose: Find Close provides the way to discard the memory that is being used by the object and allocate the object without using an explicit call to create constructor.

What are the different types of inheritance present in Delphi?
Specialization inheritance: this is the type of inheritance in which the child class is the advanced version of the parent’s class.
Class inheritance: provides a way for the child class to include the features and complete properties of the parent’s class. It is used to extend the parent class and provide the left out features and methods.
Abstract inheritance: this is the method that provides other skeleton methods which is being implemented by the child class.
Interface: this is the way by which the class implements all the skeleton methods by using the interface itself.

How does inheritance operate when using the object of the classes?
Object oriented (OO) languages, as their name implies, revolve around another aspect of the real World, where a chunk of code and data is treated as an object. An object in the real World, such as a football, has characteristics, such as size (the data), and actions, such as being kicked (a method). Such objects in an OO language are defined in a class. A class of objects, such as a class of balls, of which a football is a sub-class. The sub-class has specific features (such as a set of sewn panels) but also inherits the parent class features. It too has a size, and can be kicked. In code terms, a Football class would inherit the parent Ball class size variable (data), and kick method (code). (Reference Delphi)

What are the different types of object allocations methods in Delphi?
  • The object allocation can be done using the referencing type. This allows the object to be referenced so that no memory leak occurs.
  • Call routines are used to create the objects and used in the allocation process.
  • Use of Run Time Library functions allows the memory to be allocated to the current object that is in use.
  • The use of the functions or methods like FindFirst, FindNext and FindClose makes it possible to allocate the memory to the object.
  • Allocating the memory to the object by value is being considered as the copy gets created and it doesn’t harm the actual object.
Why is there no automation in releasing the memory automatically during the termination of the program?
Delphi uses lots of methods to do the automatic releasing of the memory like implementing the objects by reference. Objects by reference allow the memory to be freed when the object is terminated or the function of it finishes.
The object can be declared through reference as:
hello : TMy;
This way the reference of an object is created and then the object for this reference can be created as:
hello := TMy.Create;
The memory is allocated for the object by Delphi and then the create constructor method is executed to initialize the object if required.
The hello variable is used to point to the new object and then it is referenced.

How do I write a change password function for a Paradox table?
There is no way to do this within the Delphi VCL. Seems like a pretty serious omission to me. However, it is possible to do it by talking directly to the Borland Database Engine through the interface provided by the DBIPROCS and DBITYPES units. You call DbiDoRestructure, but set all the "number of" variables to zero, which makes it leave the existing values intact. I have code to do this, but it's a bit too long to include here. E-mail graham (at) if you want it.

How do abstract classes differ from Interfaces?
Abstract classes provide different placeholder methods and they have their classes extending them. Whereas, Interfaces are not classes but it, also uses the placeholder methods. Abstract classes are extended by any other class and the functions are extended to provide more functionality. Whereas, interfaces, are, not extended by any other class. Abstract class gets inherited by the new class or extended by an existing class. Whereas, interfaces placeholder’s, methods are being implemented in the class. Only one abstract class can be extended by another class. Whereas, multiple, interfaces can be implemented in one class.

What is the function of Dynamic arrays?
Dynamic arrays are the array type that defines their sizes at runtime or according to the data entered.
The dynamic arrays are declared and defined as shown below:
wishes : array of string;
SetLength(wishes, 3);
SetLength is a routine that is used to set the array size according to the string entered.
The size of the string or the input is defined at runtime that is why it is called dynamic arrays.The array size can be changed and decreased or increased according to the requirements.Dynamic arrays starts with an index 0 and it can grow according to the need of the input.

What are the reasons involved in using the interface?
  • Interfaces are used to implement the skeleton methods and provide a way through which the class can extend other classes.
  • The example shows that a sub-class can extend the bicycle class that contains mountain bike, etc.
  • They provide lots of inherited functions and features that can be added to provide unique features.
  • They are allowed to apply one method to multiple classes and extend more than one class functionality and characteristics.
  • High level classes can be defined using the interface in this case it can consists of methods and other definitions of classes.
What is Microsoft access? What is the procedure to connect Delphi application to MS access database?
Microsoft Access is primarily used for developing standalone applications. It is very fast, reliable and is very dependable when it comes to rapid application development. One of the benefits of Access from a developer's perspective is its relative compatibility with the structured query language (SQL). SQL is of course used to manipulate data within databases. So to develop efficient and dependable database applications in a rapid manner, we are going to need the advantages that MS Access offers.
Delphi is also one of the frontrunners in its field. It is also a rapid application development language that offers easy application development. One of the reasons why I choose Delphi for MS access is because it has a set of database components that integrates applications with MS Access’ Jet Engine. And since we intend to build a standalone application, Access and Delphi are perfectly place to handle this task. The aim of the application is simply to show how well MS Access and Delphi work together, among other things I will demonstrate how to use SQL to manipulate the data in the database. So let’s start with building an Access database. For the sake of brevity, we are going to use Microsoft Access to create the database, but it is also possible to programmatically create an Access database with Delphi.
The procedure to connect Delphi application to MS access database is as follows:
  • Open ODBC data sources and add a new data source with the definition of ACCESS DATA.
  • Insert a unique Data Source Name and select the database file that needs to be used.
  • Select the database source and open the Database engine configuration to set BDE configuration screen.  Choose NEW ODBC driver and provide the SQL link driver information.
  • The default ACCESS DATA will be chosen and the new Default data source name will be selected.
  • Create a Tdatabase component and set the AliasName with the name that is being defined.
  • Create a database and set the Login Prompt to FALSE. Also, add TQuery component and set the Database Name to any name that is being provided.
  • Add the TDataSource component and set the Dataset as per the TQuery component.
Request to Download PDF

Post A Comment: