Thursday, July 31, 2008

Delphi interview questions

1. What's the difference between parent and owner ?

2. What's class ?

3. Describe different concepts of oops in delphi ?

4. What's circular reference ?

5. What's the structure of a Delphi unit file ?

6. What's dll and how it can be implemented ?

7. What's overloading in Delphi ?

8. What's overriding in Delphi ?

9. What do you meant by reintroduce in delphi ?

10. What's pChar type ?

11. How an ADO connection can be established ?

12. Explain Inheritance with an example ?

13. How polymorphism can be achieved in Delphi ?

14. How to implement custom sorting in TStringList ?

15. What's the difference between TList and TObjectList ?

16. How a button can be created dynamically ?

17. What's the difference between static and dynamic loading of dlls ? How this can be implemented ?

18. What's the difference between virtual and dynamic methods ?

19. What's abstract method in Delphi ?

20. What's RTTI ?

21. Say the VCL heirarchy ?

22. What's procedural data types ?

23. What's called method hooking ?

24. For what purpose the procedure FreeAndNil is used and what's the difference between FreeAndNil and Free method ?

25. How exceptions are handled in Delphi ?

26. What's the difference between Try ...Except and Try...Finally ?

27. How to open a Text file in Delphi ?

28. What's the use of Assigned method in Delphi ?

29. What are the different access specifiers available in Delphi ?

30. What's the difference between public and protected specifier ?

31. How to register a component ?

32. What's an interface in Delphi ?

33. Is multiple inheritance available in Delphi ? How it can be implemented ?

34. What's the difference between Form and Frame ?

35. What are the global classes available in Delphi ?

36. What's the Sharemem unit used for ?

37. What are packages in Delphi?

38. Explain about DPR?

39. Describe about help file in Delphi?

40. Explain about Delphi`s VCL?

41. Explain about event handler?

42. How application server is different from other type of servers?

43. Explain about creating n tired applications using Delphi?

44. How to save images to a database with Delphi?

45. How to save binary files in Delphi?

Expect more ...

How to create DLL s using Delphi


DLL means Dynamic Link Libraries. As the name implies , dll is a collection of functions and procedures in a place which can be used in other applications. Basic idea of creating DLLs is to share functions and procedures across languages. DLL files will have an extension of .dll.

How to create a dll using Delphi

It's not so hard to create a dll as you heard. Using Delphi it's very easy. Select the menu File -> New -> Other... from Delphi IDE. This will open a dialog box. From there select the "DLL Wizard" icon . A new project will be opened with a new unit. This unit file will be little bit different from the normal unit files. In the normal units , the first line will contain a keyword unit and the respective unitname. But the unit created in dll , the first keyword will be library instead of unit as given below.

library DLLProject;


{$R *.RES}


Now you can add as many functions and procedures under the uses clause. The functions and procedures that are required to be called from other applications should be exported using the clause Exports. The name used along with the library clause will become the name of the dll. In this case our dll will be DLLProject.dll

Suppose you have 3 functions as shown below.

Function SubFunc():Integer;

Procedure SubProc();

Function MainFunc():Integer;



Here we have 2 functions and one procedure . The MainFunc is the main function which calls other 2 functions and here we are exporting MainFunc only. That means MainFunc is the only function which can be called from outside. If you need to export any other function or procedure , you have to include it under the Exports clause.

Dll loading

Now we can see how these dll [exported] functions can be called from other applications. The dll function/procedure has to be declared in the global section [before implementation section] of the unit file where the it has to be called. The syntax should be

procedure MainFunc ():Integer; external 'DLLProject.dll';



This kind of loading a dll is called static loading. Because compiler try to load the dll when it loads the application itself. So if the dll is missing in the search path , you'll get an erroro message while starting your application itself.

Now we'll see another kind of dll loading named Dynamic loading. This kind of loading require extra commands to load dll , call your dll function and release the dll from memory. The dll will be loaded in the memory whenever you call the LoadLibrary function. It won't be loaded when your application starts. So if the dll is missing in your search path, you won't get any error message during the start up of your application.

The dll should be loaded using the command LoadLibrary which returns the handle to the dll once it's loaded to the memory. If there is any problem in loading, the handle will return 0.
Once dll is loaded properly in to the memory, we have to gather the address of the function\procedure to be called. This can be done using the function GetProcAddress which returns the address of the dll function. To receive the return value , you have to have a variable of type function or procedure [TDllAddr = function : Integer; ].

Have a look at the example shown below.


TDllAddr = function : Integer;

DllAddr : TDllAddr;


DllHandle := LoadLibrary("DLLProject.dll");
if DllHandle <> 0 then
@DllAddr := GetProcAddress(DllHandle , 'MainProc');
DllAddr(); // Calling dll function


Finally, the memory allocated for the dll has to be explicitly released using the FreeLibrary function.

Note : The dll function parameters should be windows types. If you have any String type parameter in dll function/procedure , then you have include ShareMem unit in the dll. Not only that, Sharemem unit should be the first unit in the uses clause.

Delphi - The basics

Delphi is a very user friendly programming language that I have ever seen. It's based on the Pascal programming language. It's a string typed language which incorporates all the features of oops.

Delphi 2007, the eleventh and latest version, supports the Delphi programming language (Object Pascal and C++ for the 32 bit Microsoft Windows platform, and Delphi and C# for the Microsoft .NET platform.

Delphi is mainly used for the development of desktop and enterprise database applications, but it is a general-purpose software development tool suitable for most software projects.
Delphi is distributed in various versions with different features and prices: Personal, Professional, Enterprise (formerly Client/Server) and Architect. Borland Kylix is equivalent to Delphi for the Linux platform.

Versions of Delphi

Delphi 1

Delphi 2

Delphi 3

Delphi 4

Delphi 5

Delphi 6

Delphi 7

Delphi 8 [.Net version]

Delphi 2006

Delphi 2007