Thursday, 28 March 2013

Virtual and Dynamic Methods in Delphi .


To make a method virtual or dynamic, include the virtual or dynamic directive in its declaration. Virtual and dynamic methods  can be overridden in descendent classes. When an overridden method is called, the actual (run-time) type of the class or object used in the method call--not the declared type of the variable--determines which implementation to activate.
To override a method, redeclare it with the override directive. An override declaration must match the ancestor declaration in the order and type of its parameters and in its result type (if any).
In the following example, the Draw method declared in TFigure is overridden in two descendent classes:

 type
     TFigure = class
       procedure Draw; virtual;
     end;
 
     TRectangle = class(TFigure)
       procedure Draw; override;
     end;
 
     TEllipse = class(TFigure)
       procedure Draw; override;
     end;

what is Static Methods in delphi ?

Methods are by default static. When a static method is called, the declared (compile-time) type of the class or object variable used in the method call determines which implementation to activate. In the following example, the Draw methods are static:


type
     TFigure = class
       procedure Draw;
     end;
 
     TRectangle = class(TFigure)
       procedure Draw;
     end;

Tuesday, 26 March 2013

What is TClientDataSet in Delphi ?

In order to display the information from the TSQLTable (or any dbExpress dataset), we need to cache it inside a TClientDataSet component, using a TDataSetProvider component as "connector". So, drop both a TDataSetProvider and a TClientDataSet component from the Data Access tab of the Component Palette. Assign the SQLTable component to the DataSet property of the DataSetProvider, and then assign the name of the DataSetProvider to the ProviderName property of the ClientDataSet. 
As soon as you open the ClientDataSet (for example by setting the Active property to True), the content of the TSQLTable will be traversed (just once) and the records in the resultset will be provided to the ClientDataSet, which will cache them from that moment on. We can now use a DataSource and (for example) a DBGrid component to display the contents - provided by the ClientDataSet component.

Monday, 25 March 2013

What is hierarchy of VCL ?

TObject -> TPersistence -> TComponent -> TControl -> TWinControl -> TCustomEdit -> TEdit.

Friday, 22 March 2013

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;

What is the difference between TList and TStringlist?

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 maintains a list of strings.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.

Describe different concepts of oops in delphi .

OOPs concepts are -
  1. object
  2. class
  3. encapsulation
  4. abstraction
  5. polymorphism
  6. inheritance
  7. message passing
  8. dynamic binding
BASIC CONCEPT OF OOPS:
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:

An abstract method is a virtual or dynamic method that has no implementation in the class where it is declared. Its implementation is deferred to a descendent class. Abstract methods must be declared with the directive abstract after virtual or dynamic.
 For example:

 procedure DoSomething; virtual; abstract;
 
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.

For Ex.

  type
     TTextBox = class(TCustomControl)
       private
        procedure WMChar(var Message: TWMChar); message WM_CHAR;
        ...
     end;


What's is class in Delphi ?

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.

Thursday, 21 March 2013

What is RTTI in Delphi ?.

Runtime Type Information is information about an object's data type that is set into memory at run-time.
RTTI provides a way to determine if an object's type is that of a particular class or one of its descendants. The is and as operators commonly used in Delphi language.
The is operator, which performs dynamic type checking, is used to verify the actual runtime class of an object ans as operator performs checked typecasts.

Ex.
Here's a small example of the powers of the RTTI. This example shows how to obtain the ancestry of a component using the ClassType and ClassParent properties. It uses a button and a list box on a form. When the user clicks the button, the name of the button’s class and the names of its parent classes are added to the list box (found in the Delphi Help).

procedure TForm1.Button1Click(Sender: TObject) ;

var
   ClassRef: TClass;
begin
   ListBox1.Clear;
   ClassRef := Sender.ClassType;
   while ClassRef <> nil do
   begin
     ListBox1.Items.Add(ClassRef.ClassName) ;
     ClassRef := ClassRef.ClassParent;
   end;

end;

Wednesday, 20 March 2013

What is different between Forms and DataModule in Delphi .

Ans.
     On the Forms you can place visual and non visual component  (Ex. Tlable, Tbutton, Adotable). but on the  Data  module you can place only non visual component.

When working with a large number of records in the dataset, what DataSet method should the application call to prevent data - aware controls from updating every time t he active record changes?

a) BlockUpdate
b) DisableControls
c) Disable
d) None of the above
 
Answer: b. DisableControls 

Which generics classes will destroy an object when they are removed from the list, assuming the list owns the object? ( Choose all that apply )

a) TList
b) TObjectList
c) TDictionary
d) TObjectDictionary
e) TObjectList and TObjectDictionary.
 
Answer : e. TObjectList and TObjectDictionary

In which memory area are local variables and procedure parameters stored?

a) Stack
b) Heap
c) Random access area
d) None of above.
 
Answer : a. Stack

In the Delphi language, which symbols or words define the declaration of an attribute?

a) { }
b) < >
c) [ ]
d) & &
e) None of the above
 
Answer :c. [ ]

Delphi Package can contain components, non - visual classes, but not forms.

a) True
b) False
 
Answer : b. False

Which of the follo wing is not a valid calling convention for 32 - bit Delphi routines?

a) register
b) dynamic
c) stdcall
d) cdecl
 
Answer :b. dynamic
 

What is the underlying type of the TDateTime type?

a)  Double
b) TObject
c) String
d) Integer
 
Answer : a: Double

In the Delphi language, which symbols or words define the start and end of a code block?

 
a) { }
b) [ ]
c) start end
d) begin end.
 
Answer : D : begin end.
 

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

What is Different between Parent and Owner in Delphi.

Parent is immediate ancestor of Component. IT provide To context to draw the controls.

Owner is the component responsible for making sure it's destroyed and Container of All Component is also known as Owner.