Tuesday, 11 October 2022

What is Reintroduce ?

 A derived class uses the reintroduce directive to hide the name of a virtual or dynamic method was declared in a base class.

Example:-

 type

  TBooks = class

    public

      procedure Add(Item: Integer); virtual;

  end;

  TMathBook = class

    public

      // The TMathBook.Add method hides TBooks.Add, so that compiler warn you about this.

      procedure Add(Item: Single);reintroduce;

  end;

Thursday, 29 September 2022

What is difference between Virtual and Dynamic ?

 virtual and dynamic methods are semantically equivalent. However, they differ in the implementation of method-call dispatching at run time: 

virtual methods optimize for speed, while dynamic methods optimize for code size.

About the design patterns and its Type

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Object oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved.

  • Singleton :- A class of which only a single instance can exit.
  • Abstract Factory :- Create an instance of several families of classes.
  • Factory Method :- Create an instance of several derived classes.
  • Builder :- Separates object construction from its representation.
  • Prototype :- A fully initialized instance to be copied or cloned.
  • Object Pool :- Avoid expensive acquisition and release of resources by recycling objects that are no longer use. 

Tuesday, 28 October 2014

How can fetch Top N Records from database. ?

Q) How can fetch Top N Records from database. ?
Ans :- Returning only the first N records in a SQL query differs quite a bit between database platforms. Here's some samples:
  
Microsoft SQL Server
    SELECT TOP 10 column FROM Table-name 
PostgreSQL and MySQL
    SELECT column FROM Table-name LIMIT 10
Oracle
SELECT column FROM Table-name WHERE ROWNUM <= 10
Firebird
SELECT FIRST 10 column FROM table
InterBase 
SELECT * FROM Table-name rows 10

Thursday, 15 May 2014

Q :) How to create table in firebird database ?
Ans :-  create table teacher(
 uid int not null,
 pid int,
 Fname varchar(50),
 Lname varchar(50),
 Qualification char(10),
 dob date,
 Address varchar(150),
 pincode char(10),
 dist varchar(50),
 state varchar(50),
 officePhNo varchar(50),
 phno varchar(50),
 mobile varchar(50),
 emailID varchar(50),
 lastupdation timestamp,
 modby varchar(50));

 alter table teacher add constraint pk_TeacherUID primary key (uid)

 create generator gn_TeacherUID

 create trigger tggBI_TeacherUID for teacher
 active before insert position 0
 as
 begin
   if (new.UID is null) then
   begin
    new.uid = gen_id(gn_teacheruid,1);
   end
 end;

Thursday, 17 April 2014

Q) How to create TStringList in delphi ?
Ans) procedure GoodTStringListUsing;
    var
      X: TStringList;
      i: Integer;
    begin
      X := TStringList.Create;
      try
        X.Add('Animals');
        X.Add('Flowers');
        X.Add('Cars');
        X.Sort; { Find will only work on sorted lists! }

        Memo1.Clear;
      for i:=0 to X.Count-1 do begin
         Memo1.Lines.Add(X.Strings[i]);
   end;
     finally
       X.Free;
   end;
end;


Sunday, 2 February 2014

Q) Explain about Delphi`s VCL?
Ans. Delphi is easier to use rather than the API`s. It has strong windows connection and Borland has made things possible for portability on windows. It has a strong library and it maps windows 32. It supports API`s for properties and events. Borland is taking enough measures for back portability for windows.
Q) What is project file in delphi?
Ans. File with .dpr extension is the project file. It comprises all the unit names used in the application along with their path in the hard disk (and the form name if the unit is associated with a .dfm file). It also instantiates the auto-create forms. We can also write code for application initialisation in begin..end blocks in .dpr file.
Q) Explain about event handler?
Ans. Use for event handlers for make sure that the transactions and operations confirm to the business code of ethic. They can significantly affect the data packets which are being sent out to the server for update. Data packets are very useful in giving critical updates at runtime.
Q ) Explain about DPR ?


Ans.Apart from two important files (PAS and DFM) there is a third file known as (DPR) or Delphi project file. Delphi project file is automatically built by the compiler. There are two ways to edit the file one is through manually and the other is through Delphi project manager. The source file which you will be seeing is a Pascal source file. 
Q) What is the use of UDL files in Delphi?
Ans. If you want to store the server connection information outside the application which can be retrieved later during connecting time. This is very useful in creating UDL files which are very helpful where hard coded connection string is not acceptable. Also try to save the documents in the form of .udl which will help you to connect databases easily.

Q) What is the procedure to access the database from Delphi ?

Ans. - To access the database the BDE needs to be configured as it defines an alias for the database that has to be connected. 

- The configuration allows the avoidance of coding the directory path and it just takes the referring of the alias. 

- The creation of three objects is required to access the database and that includes: Query or table object that in synchronization with the alias and it also fetches some data. 

- Data source object that allows the linking between the data and the controls used to connect the database. 

- Setting the active property on the table or query to TRUE will open the database and allow the accessing to be done.

Thursday, 18 July 2013

what is TADOQuery component for Delphi?

TADOQuery component is aimed at execution of SQL-commands. It can be considered as an analog of TSQLQuery component from dbExpress. Connection to the database is set via Connection or ConnectionString properties. Query text is written to SQL property. If a query returns the dataset one should use Open() method or Active=true property. If a query does not return the dataset, it shall be run using ExecSQL method. ExecSQL returns the number of records processed during a query running. The same value is contained in RowsAffected property.

Wednesday, 17 July 2013

What is TADOConnection in Delphi

TADOConnection component connects to the data storage. TADOConnection resembles TSQLConnection component. The difference between them is that when working with TSQLConnection connection parameters are set via ConnectionNameDriverName and Paramsproperties. In TADOConnection all connection parameters are set via ConnectionString property. Moreover, it is possible to specify file name with connection parameters as a connection string in TADOConnection.

Connection String with Firebird database in Delphi XE2

procedure TForm1.Button1Click(Sender: TObject);
var 
 Conn: TSQLConnection;
begin
  Conn := TSQLConnection.Create(Self);
  try
    Conn.DriverName := 'Provider=MSDASQL.1; '+
                       'Persist Security Info=False; '+
                       'Data Source=DataBaseName; '+
                       'Initial Catalog=DataBaseName';'; 
    Conn.Params.Add('User_Name=SYSDBA');
    Conn.Params.Add('Password=masterkey');

    // Replace the dbname in the next line with the
    // value obtained at runtime, as  in
    // Conn.Params.Add('Database=' + YourNewPathAndDBName);
    Conn.Params.Add('Database=D:\FolderName\DataBaseName.fdb');

    Conn.Open;
    if Conn.Connected then
      ShowMessage('Connection successfully made to DB');
  finally
    Conn.Free;
  end;
end;

Monday, 8 July 2013

Q :- What is the difference between the SuperServerclassic and embedded servers ?

Ans:-SuperServer is a single-process multi-threaded server (like Apache on Windows, for example) Classic is a multi-process single-threade server - things are synced via a separate lock manager process Embedded is a DLL you hook up to your application and work with database file directly
SuperServer is good for OLTP, lot of users, etc. Classic is good for OLAP or few users running heavy queries. Embedded is good for desktop apps.
You should install and use SuperServer while developing, since embedded only allows one connection at a time, so you cannot access the database from your application and administration tool at the same time. Later, you can deploy using any of those 3 architectures.

Thursday, 18 April 2013

Simple Application in VB.Net


Public Class Form1
    Dim sqlconnection As New System.Data.SqlClient.SqlConnection
    Dim sqlCommand As New System.Data.SqlClient.SqlCommand
    Dim sqlDataAdapter As New System.Data.SqlClient.SqlDataAdapter
    Dim cmdBuilder As System.Data.SqlClient.SqlCommandBuilder
    Dim dsDataset As New DataSet
    Dim cmCurrency As CurrencyManager
    Dim LastUID As Integer = 0
    Dim newrow As DataRow

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New DataTable
        sqlconnection.ConnectionString = "Data Source=Manoj;Initial Catalog=imported_data;User ID=sa;Password=sa"
        sqlCommand.CommandText = "select * from mstcompanies"
        sqlCommand.Connection = sqlconnection
        sqlDataAdapter.SelectCommand = sqlCommand

        cmdBuilder = New System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter)
        sqlDataAdapter.Fill(dt)
        DataGridView1.DataSource = dt

        txtUID.Text = dt.Rows(0).Item(0)
        txtName.Text = dt.Rows(0).Item(2)
        txtAddress.Text = dt.Rows(0).Item(4)
        txtCity.Text = dt.Rows(0).Item(5)

        dsDataset.Tables.Add(dt)
        dsDataset.Tables(0).TableName = "mstcompanies"
        sqlDataAdapter.TableMappings.Add(New System.Data.Common.DataTableMapping("Table", "mstCompanies"))

        Call bindFields(dt)
        cmCurrency = BindingContext(DataGridView1.DataSource, DataGridView1.DataMember)
    End Sub
    Public Function bindFields(ByVal dtSrc As DataTable)
        txtUID.DataBindings.Add("Text", dtSrc, "UID")
        txtName.DataBindings.Add("Text", dtSrc, "Name")
        txtAddress.DataBindings.Add("Text", dtSrc, "Address")
        txtCity.DataBindings.Add("Text", dtSrc, "City")
    End Function

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        txtUID.Text = ""
        txtName.Text = ""
        txtAddress.Text = ""
        txtCity.Text = ""

        newrow = dsDataset.Tables("mstCompanies").NewRow
        LastUID = dsDataset.Tables("mstcompanies").Rows(dsDataset.Tables("mstcompanies").Rows.Count - 1).Item("UID")
        txtUID.Text = LastUID + 1
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        With dsDataset.Tables("mstcompanies")

            If txtName.Text = "" Then
                MsgBox("Please Enter Company Name")
                Exit Sub
            End If

            dsDataset.Tables("mstcompanies").Rows.Add(newrow)
            newrow.Item("UID") = txtUID.Text + 1
            newrow.Item("Name") = txtName.Text
            newrow.Item("Address") = txtAddress.Text
            newrow.Item("City") = txtCity.Text

            sqlDataAdapter.Update(dsDataset)
            MsgBox("Record Save Successfully.")


        End With
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        cmCurrency.RemoveAt(cmCurrency.Position)
        sqlDataAdapter.Update(dsDataset)
        MsgBox("Record Delete Successfully.")
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        dsDataset.Tables("mstCompanies").Rows(cmCurrency.Position).Item("Name") = txtName.Text
        dsDataset.Tables("mstCompanies").Rows(cmCurrency.Position).Item("Address") = txtAddress.Text
        dsDataset.Tables("mstCompanies").Rows(cmCurrency.Position).Item("City") = txtCity.Text
        sqlDataAdapter.Update(dsDataset)
        MsgBox("Record Update Successfully.")
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        cmCurrency.Position = cmCurrency.Position - 1

    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        cmCurrency.Position = cmCurrency.Position + 1
    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        cmCurrency.Position = 0
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        cmCurrency.Position = cmCurrency.Count
    End Sub
End Class

Thursday, 11 April 2013

What is a Delphi unit?


A Delphi unit is a separate file used to store procedures and functions. If you know what a form is, a unit is exactly the same, except it has no visual interface. So you can't put windows controls on it like buttons and edit boxes. A form has windows controls and their associated code behind them, a unit only has the code.
They are useful if you have some functions that you use often from many different forms and you only want to write them once. For example:
function LeftStr(const S : String; Index : Integer) : String; 
begin 
If Index <= 0 
then 
Result := '' 
else 
Result := Copy(S, 1, Index); 
end;
function RightStr(const S : String; Index : Integer) : String; 
begin 
If Index > Length(S) 
then 
Result := '' 
else 
Result := Copy(S, Index, (Length(S)-Index+1)); 
end; 

Then you can have your unit's name in a forms uses clause and then use the functions LeftStr and RightStr from several different forms.

Tuesday, 9 April 2013

What is the function of Inheritance in Delphi?


  • The inheritance needs a parent and a child class where the child class inherits the property of the parent class. 
  • Child can have their own functions or inherit functions and properties from the parent class. 
  •  TFootball child class is the base class and inheriting the properties of TBall class of the parents. 
  • For Ex.
var
beachBall : TBall;
soccerBall : TFootball;
begin
beachBall := TBall.Create(5);
soccerBall := TFootball.Create(5, 12);

beachBall.Kick(10);
soccerBall.Kick(10);

ShowMessageFmt('Beach ball is moving at speed : %d',[beachBall.GetSpeed]);
ShowMessageFmt('Soccer ball is moving at speed : %d',[soccerBall.GetSpeed]);
end;

The output is shown as such:
Beach ball is moving at speed: 12
Soccer ball is moving at speed: 12

How does inheritance operate when using the object of the classes?


- The inheritance needs a parent and a child class where the child class inherits the property of the parent class. Child can have their own functions or inherit functions and properties from the parent class. 
TFootball child class is the base class and inheriting the properties of TBall class of the parents. 

For Ex.

var
beachBall : TBall;
soccerBall : TFootball;
begin
beachBall := TBall.Create(5);
soccerBall := TFootball.Create(5, 12);

beachBall.Kick(10);
soccerBall.Kick(10);

ShowMessageFmt('Beach ball is moving at speed : %d',[beachBall.GetSpeed]);
ShowMessageFmt('Soccer ball is moving at speed : %d',[soccerBall.GetSpeed]);
end;

The output is shown as such:
Beach ball is moving at speed: 12
Soccer ball is moving at speed: 12