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.