1. What is the difference between Parent and Owner?
Parent is the Window control where the control is displayed. Owner is the component responsible for making sure it's destroyed.
When a component is created, an owner (which is another component) is specified as a parameter to the Create method. Unless the component is destroyed earlier, the owner will automatically free the component when the owner is destroyed. This is the purpose of ownership.
Controls that appear on the screen need to know where to paint themselves, hence the parent property. It specifies the visual container for the control. This property must be specified before a control can be displayed.
When a component is dropped on a form at design time, the owner is the form and the parent is the container on which it is dropped. For example, drop a group box on a form. Its owner and parent are both the form. Drop a check box on the group box. Its owner is the form and its parent is the group box.
The specification of owner and parent are at the programmer's discretion when controls are created dynamically and so the above relationships may not hold. This is especially true with composite components. With run-time creation of controls, the programmer may specify any component to be an owner (including a nil owner) and any window control as the parent. If a nil owner is specified, the programmer is responsible for explicitly freeing the object.
2. What's class ?
A class is a collection of objects having common features .It is a user defined data types which has data members as well functions that manipulate these data's.
3. Describe different concepts of oops in delphi ?
OOPs concepts are- object
- class
- encapsulation
- abstraction
- polymorphism
- inheritance
- message passing
- dynamic binding
1.OBJECTS:
An object is an abstraction of a real world entity. It may
represent a person,a place, a number and icons or something
else that can be modelled.Any data in an object occupy some
space in memory and can communicate with each other.
2.CLASSES:A class is a collection of objects having common
features .It is a user defined data types which has data
members as well functions that manipulate these data's.
3.ABSTRACTION:
It can be defined as the separation of unnecessary
details or explanation from system requirements so as to
reduce the complexities of understanding requirements.
4.ENCAPSULATION:
It is a mechanism that puts the data and function together.
It is the result of hiding implementation details of an
object from its user .The object hides its data to be
accessed by only those functions which are packed in the
class of that object.
5.INHERITANCE:
It is the relationship between two classes of object such
that one of the classes ,the child takes all the relevant
features of other class -the parent.
Inheritance bring about re-usability.
6.POLYMORPHISM:
polymorphism means having many forms that in a single
entity can takes more than one form.Polymorphism is
implemented through operator overloading and function
overloading.
7.DYNAMIC BINDING:
Dynamic binding is the process of resolving the function to
be associated with the respective functions calls during
their run time rather than compile time.
8.MESSAGE PASSING:
Every data in an object in oops that is capable of
processing request known as message .All object can
communicate with each other by sending message to each other
4. What's circular reference ?
http://blog.spreendigital.de/2011/06/09/solving-circular-unit-references-with-class-helpers/
The solution is that you can have two unique USES lines in each unit. One can go in the INTERFACE section, and another in the IMPLEMENTATION section. If UNIT A uses UNIT B in it's INTERFACE section, and UNIT B uses UNIT A in it's IMPLEMENTATION section, the circular reference is avoided, and all is well.
5. What's the structure of a Delphi unit file ?
unit MyUnit; //unit nameinterface
{ In this section the routines (types, variables) are specified that are available for use in other units }uses
{ The list of the unit names whose routines our unit wants to use }implementation
{ This section contains all the source code that defines all the types listed/defined in the interface section }uses
{ The optional list of the unit names with routines our unit wants to use }
initialization
{ This optional section contains all source code needed to be executed when the unit is referenced for the first time - to initialize any data the unit uses}finalization
{ This optional section is required only if we have the initialization section. Here we write the code we need to be executed when the form is removed from memory. If your unit needs to perform any cleanup when the application terminates, such as freeing any resources allocated in the initialization part; you can add the cleanup code into the finalization section}end. //unit end
6. What's dll and how it can be implemented ?
7. What's Virtual in Delphi ?
Virtual : Allows a class method to be overriden in derived classes
| Description |
| The Virtual directive allows a method in a class to be overriden (replaced) by a same named method in a derived class. You would mark a function or procedure as Virtual when you happily allow a programmer who creates a class based on your class to replace its functionality. For example, you might allow a base class to paint a canvas in white, but allow a derived class to paint a picture on the canvas instead. Here, the virtual directive is allowing the code to be extended, to be enriched. Virtual may be followed by the Abstract directive. This modifies the effect of the virtual directive. It means that the current class must not code the method - it is there only as a placeholder to remind and ensure that derived classes implement it. |
| Notes |
| Virtual is semantically equivalent to Dynamic. The former is optimised for speed, the latter for memory. |
8. What's Abstract in Delphi ?
| Abstract | Defines a class method only implemented in subclasses |
| Class | Starts the declaration of a type of object class |
| Function | Defines a subroutine that returns a value |
| Overload | Allows 2 or more routines to have the same name |
| Override | Defines a method that replaces a virtual parent class method |
| Procedure | Defines a subroutine that does not return a value |
| Dynamic | Allows a class method to be overriden in derived classes |
| AbstractErrorProc | Defines a proc called when an abstract method is called |
| Function | Defines a subroutine that returns a value |
| Inherited | Used to call the parent class constructor or destructor method |
| Overload | Allows 2 or more routines to have the same name |
| Override | Defines a method that replaces a virtual parent class method |
| Procedure | Defines a subroutine that does not return a value |
| Virtual | Allows a class method to be overriden in derived classes |
| Dynamic | Allows a class method to be overriden in derived classes |
| Abstract | Defines a class method only implemented in subclasses |
| Function | Defines a subroutine that returns a value |
| Override | Defines a method that replaces a virtual parent class method |
| Procedure | Defines a subroutine that does not return a value |
Abstract : Defines a class method only implemented in subclasses
| Description |
| The Abstract directive defines a class method as being implemented only in derived classes. It is abstract in the sense that it is a placeholder - it has no implementation in the current class, but must be implemented in any derived classes. It is used where the base class is always treated as a skeleton class. Where such a class is never directly used - only based classes are ever instantiated into objects. For example, a TAnimal class may have an abstract method for how the animal moves. Only when creating, say, a TCatclass based in TAnimal will you implement the method. In this instance, the cat moves by walking. An Abstract class must be used to qualify a virtual class, since we are not implementing the class (see Virtual for more details). |
| Notes |
| If you create an instance of a class that has an Abstractmethod, then delphi warns you that it contains an uncallable method. If you then try to call this method, Delphi will try to callAbstractErrorProc. If not found, it will throw anEAbstractError exception. |
9. What's overloading in Delphi ?
Overload : Allows 2 or more routines to have the same name
| Description |
| The Overload directive allows you to have different versions of the same named function or procedure with different arguments. This is useful when there are a number of ways that code may want to use the routine. For example, if the routine is a class constructor, you may want one version of Create that sets default values, and another that takes these values as parameters. You must code the Overload directive before any other directives. When calling an overloaded routine, Delphi chooses the appropriate version based first on number of arguments, then on the argument types. If it cannot make a decision, it throws an exception. When the argument count is the same, it always tries to satisfy the simplest/smallest data types first - for example, the above value 23 would satisfy a Byte argument ahead of an Integer argument. Sometimes, you can avoid the need for overloading by giving final arguments default values. The caller can then call with or without these final parameters. procedure MyProc(a : Byte; b : Byte = 23); can be called in two ways: MyProc(15, 16); MyProc(45); // Defaults b to value 23 Overloading is not restricted to class methods. In line functons and procedures can be similarly overloaded. |
10. What's overriding in Delphi ?
Override : Defines a method that replaces a virtual parent class method
| Description |
| The Override directive defines a class method as overriding the same named method in a parent class. For example, you might want to override (replace) the operation of the constructor to take into account the class changes introduced by your class. You can only override classes defined as virtual ordynamic (the latter are beyond the scope of Delphi basics). Only those methods that can be sensibly overriden by a derived class are normally allowed to do so. If a method is marked as abstract as well as virtual then you must override it and implement it for it to be useable by a user of your class. |
11. What do you meant by reintroduce in delphi ?
http://www.delphibasics.co.uk/RTL.asp?Name=Procedure
http://stackoverflow.com/questions/53806/reintroducing-functions-in-delphi
http://www.delphigroups.info/2/6/373133.html
12. What's pChar type ?13. How an ADO connection can be established ?
Provider=Advantage.OLEDB.1;
Password=******;
User ID=ADSSYS;
Data Source=F:\Working System\Teller\Teller\Data\CoreDictionary.add;Initial Catalog="";
Mode=ReadWrite
;Extended Properties="ServerType=ADS_LOCAL_SERVER";
Advantage Character Data Type=ADS_ANSI;
Advantage Compression="";
Advantage Encryption Password="";
Advantage Filter Options=IGNORE_WHEN_COUNTING;
Advantage Locking Mode=ADS_PROPRIETARY_LOCKING;
Advantage Security Mode=ADS_CHECKRIGHTS;
Advantage Server Type=ADS_LOCAL_SERVER;
Increment User Count=FALSE;
Show Deleted Records in DBF Tables with Advantage=FALSE;Stored Procedure Connection=FALSE;
Advantage Table Type=ADS_ADT;
Trim Trailing Spaces=FALSE;
Use NULL values in DBF Tables with Advantage=FALSE
Provider=SQLOLEDB.1;Password=xxxxxxxx;Persist Security Info=True;User ID=Sa;Initial Catalog= TEMPSA; Data Source=TEMP/SQLEXPRESS;
Provider=OraOLEDB.Oracle.1;Password= xxxxxxxx;Persist Security Info= True;User ID= TEMPSA;Data Source= Localhost
14. Explain Inheritance with an example ?
15. How polymorphism can be achieved in Delphi ?
16. How to implement custom sorting in TStringList ?
17. What's the difference between TList and TObjectList ?
http://www.3dbuzz.com/vbforum/showthread.php?159422-Record-TList-TObjectList
http://stackoverflow.com/questions/10410019/use-of-tlist-and-tobjectlist
18. How a button can be created dynamically ?
19. What's the difference between static and dynamic loading of dlls ? How this can be implemented ?
20. What's the difference between virtual and dynamic methods ?
21. What's abstract method in Delphi ?22. What's RTTI ?
RTTI - Runtime type informartion, we can use is and as key work we can use at runtime.
Using is we can find the control at run time
Using as we can create control at run time23. Say the VCL heirarchy ?
Delphi's components reside in a component library that includes the Visual Component Library (VCL) and the Component Library for Cross-Platform (CLX). The following figure shows the relationship of selected classes that make up the VCL hierarchy. The CLX hierarchy is similar to the VCL hierarchy but Windows controls are called widgets (therefore TWinControl is called TWidgetControl, for example), and there are other differences. For a more detailed discussion of class hierarchies and the inheritance relationships among classes, see Object-oriented programming for component writers For an overview of how the hierarchies differ from each other, see WinCLX versus VisualCLXand refer to the CLX online reference for details on the components.
The TComponent class is the shared ancestor of every component in the component library. TComponent provides the minimal properties and events necessary for a component to work in the IDE. The various branches of the library provide other, more specialized capabilities.
When you create a component, you add to the component library by deriving a new class from one of the existing class types in the hierarchy.
24. What's procedural data types ?
25. What's called method hooking ?26. For what purpose the procedure FreeAndNil is used and what's the difference between FreeAndNil and Free method ?
Free - Deallocate the memory previously allocated for the object
nil - Dereference the object
When an object is created like
Query1 := TQuery.Create(nil)
It creates the instance and allocate some memory space to hold the data of Query1
When Free is called - It frees the memory of space already allocated for Query1
When nil is called - It sets the pointer to nil
Always try to use FreeAndNil instead of Free And Nil separately
27. How exceptions are handled in Delphi ?
28. What's the difference between Try ...Except and Try...Finally ?
29. How to open a Text file in Delphi ?30. What's the use of Assigned method in Delphi ?
Tests for a nil (unassigned) pointer or procedural variable.
Unit
System
Category
pointer and address routines
Delphi syntax:
function Assigned(const P): Boolean;
Description
Use Assigned to determine whether the pointer or procedure referenced by P is nil. P must be a variable reference of a pointer or procedural type. Assigned(P) corresponds to the test P<> nil for a pointer variable, and @P <> nil for a procedural variable.
Assigned returns false if P is nil, true otherwise.
Note: Assigned can't detect a dangling pointer--that is, one that isn't nil but no longer points to valid data. For example, in the code example for Assigned, Assigned won't detect the fact that P isn't valid.
31. What are the different access specifiers available in Delphi ?
32. What's the difference between public and protected specifier ?33. How to register a component ?
initialization
RegisterClass(TfraPasswordMaint);
34. What's an interface in Delphi ?
35. Is multiple inheritance available in Delphi ? How it can be implemented ?
36. What's the difference between Form and Frame ?
37. What are the global classes available in Delphi ?
38. What's the Sharemem unit used for ?
39. What are packages in Delphi?
40. Explain about DPR?
41. Describe about help file in Delphi?
42. Explain about Delphi`s VCL?
43. Explain about event handler?
44. How application server is different from other type of servers?
45. Explain about creating n tired applications using Delphi?
46. How to save images to a database with Delphi?
47. How to save binary files in Delphi?
48. Whatis the difference between TList and TStringlist?
http://delphifaqs.blogspot.in/
Tlist is used to stores an array of pointers, is often used to maintain lists of objects. TList has properties and methods to
- Add or delete the objects in the list.
- Rearrange the objects in the list.
- Locate and access objects in the list.
- Sort the objects in the list.
TStringList is used to
- Add or delete strings at specified positions in the list.
- Rearrange the strings in the list.
- Access the string at a particular location.
- Read the strings from or write the strings to a file or stream.
- Associate an object with each string in the list.
- Store and retrieve strings as name-value pairs.
- Sort the strings in the list.
- Prohibit duplicate strings in sorted lists.
- Respond to changes in the contents of the list.
- Control whether strings are located, sorted, and identified as duplicates in a case-sensitive or case-insensitive manner.
49. Can Objects be assigned to a TStringList?
Well if someone asks that can we store an object in a TStringlist or should we use only TList for this purpose, the answer should be ----> Yes ofcourse!.
Now how to do that and where can I use such facility. Now first to answer why should we require this feature if at all. One place where we can use such a feature is when we are required to save or associate an object to a particular name, like saving a location name with the corresponding bitmap.
Now coming to how to do that in delphi. The answer is using the Objects property associated with TStringlist. Delphi gives the power of associating objects to tstringlist using this simple property.
Please see the below example to see how to do that -
Here in this example add a button to a simple delphi form. Now add two edit texts and add a TMemo component. Now write the following code on the button click event -
procedure TForm1.Button2Click(Sender: TObject);
var
mystringlist : tstringlist;
begin
Memo1.clear;
mystringlist := tstringlist.create();
mystringlist.Add(edit1.text);
mystringlist.Objects[0] := edit1;
mystringlist.Add(edit2.text);
mystringlist.objects[1] := edit2;
memo1.Lines.Add(TEdit(mystringlist.objects[0]).name);
memo1.Lines.Add(TEdit(mystringlist.objects[1]).name);
end;
Run the delphi program by pressing F9 key or navigating to "Run" Menu and clicking on "Run" Menu item.
Now click on the button on the form and you will see that memo displays two strings edit1 and edit2. Here the names have been derieved from the objects stored in the stringlist.
This was just a demonstration program and the power of such a feature can be easily utilized in performing complex tasks.
50. Difference between Owner and Parent??
Whenever we try add a button on a panel in a form, we try to make an invisible connection between the components. As we add the button on the panel, the panel automatically is set as the Parent of the button while the form becomes the owner.
Owner property is a read only property and cannot be modified, however parent for a control can be set easily using the following code:
button1.parent := form1; // this could be to any control
If we try to create a new component say at runtime, then we need to set the parent property of the control to make it visible.
The Owner component basically takes the responsibility of freeing the allocated memory of the owned components. The Owner is being set while invoking the create constructor and becomes a read-only property so can't be changed later on.
The Parent component on the other end determines how the child (i.e. contained component is to be displayed). All the properties like left, top etc are relative to the parent component.
(Note: Form is the owner of all the components residing inside it. So whenever the form is displayed then all the components memory is freed automatically.)
To understand the concepts lets develop a test code...
So, open delphi and open a form. Place a button on the form say button1. Place two edit text on the form say edit1 and edit2.
Double click on button1 and write the following code (View the sample code below):
procedure TForm1.Button1Click(Sender: TObject);
var
myform : tform;
begin
edit1.text := '';
edit2.text := '';
myform := tform.create(self);
myform.parent := button1;
myform.visible := true;
myform.caption := 'MyForm';
Edit1.Text := 'Owner: ' + myform.owner.name;
edit2.text := 'Parent: ' + myform.parent.name;
end;
Run the program and you will see that as you click on the button1. A form is displayed inside the button1 control... :)... Nice.. Hmmm.. Well all this happened because we have set the parent of our form (i.e. myform as button).
Well now you may ask what if I don't set the parent property. Well the answer is simple your form won't get displayed as delphi doesn't knows which form/control should display our form.
Now, you say what if I would have set parent of myform as form1 rather than button1. The answer is that our form i.e. myform will be displayed withing form1 now and will be visible withing the boundaries of form1... :)..
Now what if I say that we live in a free world and our newly created form has been bounded within form1. What should I do. Hmm now that pretty simple. Simply set the parent property of our form to nil. This will let our form be created outside the boundaries of form1. The code for this will be:
procedure TForm1.Button1Click(Sender: TObject);
var
myform : tform;
begin
edit1.text := '';
edit2.text := '';
myform := tform.create(nil);
myform.parent := nil;
myform.visible := true;
myform.caption := 'MyForm';
try
Edit1.Text := 'Owner: ' + myform.owner.name;
Edit2.text := 'Parent: ' + myform.parent.name
except
end;
end;
51. Function String_Reverse(S : String): String;
Var
i : Integer;
Begin
Result := '';
For i := Length(S) DownTo 1 Do
Begin
Result := Result + Copy(S,i,1) ;
End;
End;