Pages

C3 Health Services

Visit Official Website 9278982994

Expert Healthcare at Your Doorstep

Tuesday, 28 August 2012

How to use TADOTable in Delphi XE2?

Following is the code snippet which will show you how to use TADOTable in Delphi XE2?

procedure TClass1.GetDataFromADOTable;
begin
  try
    if SetADOTable then
    begin
      if tADOTable.Locate('ColumnA;ColumnB', VarArrayOf([ValueA, ValueB]), [loPartialKey])  then
      begin
        VarX := tADOTable.FieldByName('ColumnX').AsInteger;
        VarY := tADOTable.FieldByName('ColumnY').AsInteger;
      end;
    end;
  except
    on E : Exception do
    begin
      ShowMessage('Error occured in function GetDataFromADOTable: ' + E.Message);
      exit;
    end;
  end;
end;

function TClass1.SetADOTable : boolean;
begin
  try
    tADOTable.Connection := ADOConnection;  //Connectin name
    tADOTable.TableName := 'myTableName';  //Table name
    tADOTable.Open;
    result := true;
  except
    on E : Exception do
    begin
      result := false;
      ShowMessage('Error occured in function SetADOTable: ' + E.Message);
      exit;
    end;
  end;
end;

Explanation: Lets discuss the SetADOTable function first. It assings TADOTable with connection name and table name and then it opens the table. Here all data is fetched in the ADOTable from myTableName table. Now come to the function GetDataFromADOTable. It checks if there is data in ADOTable, locates a pointer to a particular column/columns by using locate keyword. Then it fetches the values in VarX and VarY.

Monday, 27 August 2012

How to use TADOQuery in Delphi XE2?

Following is the code snippet which will show you how to use ADOQuery in Delphi XE2?

function TClass1.UseADOQuery : integer;
begin
  try
    with qryADOQuery do
    begin
      Connection := ADOConnection; //Connection name
      Close;
      SQL.Clear;
      SQL.Text :=
        'SELECT ColumnX FROM TableA WHERE ' +
        'ColumnA = :ParameterA AND ' +
        'ColumnB = :ParameterB AND ' +
        'ColumnC = :ParameterC';

      Parameters.ParamByName('ColumnA').Value := ParameterA;
      Parameters.ParamByName('ColumnB').Value := ParameterB;
      Parameters.ParamByName('ColumnC').Value := ParameterC;
      Open;
      if (Recordcount = 0) then
        result := 0
      else
        result := Fields.FieldByName('ColumnX').Value; //Assume ColumnX value is an integer
      Close;
    end;
  except
    on E : Exception do
    begin
      result := 0;
      ShowMessage('Error occured in function UseADOQuery: ' + E.Message);
      exit;
    end;
  end;
end;

Explanation:First of all query has be be initialized with connection name. Now close it if already opened. For being on safer side, we should close it first before using it. Clear the SQL statement if any then write new SQL statement. Parameters to the query are passed by using colon (:) keyword. Recordcount keyword returns the number of rows affected.

OnShortCut event of Delphi XE2 Forms


This article is about OnShortCut event of Delphi Forms. Lets discuss the requirement first.

Requirement: Assme that I have two Delphi forms in my project (MyForm1 and MyFrom2). Now my requirement is that, if I am on MyForm1 and press ESC, I should go to MyForm2 and vice versa.

Consider the code of MyForm1:

unit uf_MyUnit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.ComCtrls;

type
  TfMyUnit1 = class(TForm)
    procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);  
  private
  
  public

  end;

var
  fMyForm1: TfMyUnit1;

implementation

uses uf_MyUnit2;

{$R *.dfm}

procedure TfMyUnit1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
   case Msg.CharCode of
      27 : begin
             Handled := true;
             fMyForm2.Show;
             fMyForm1.Close;
           end;
   end;
end;

end.

Explanation: Remember to add FormShortCut function on the OnShortCut event of the form. By adding this function on the OnShortCut event of the form, this function will immediately gets fired when any key is pressed. '27' is the keycode for ESC key. So when ESC key is pressed fMyForm2 is displayed and current form is closed.

Similar is the code for MyForm2:

unit uf_MyUnit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.ComCtrls;

type
  TfMyUnit2 = class(TForm)
    procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);  
  private
  
  public

  end;

var
  fMyForm2: TfMyUnit2;

implementation

uses uf_MyUnit1;

{$R *.dfm}

procedure TfMyUnit2.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
   case Msg.CharCode of
      27 : begin
             Handled := true;
             fMyForm1.Show;
             fMyForm2.Close;
           end;
   end;
end;

end.

Saturday, 25 August 2012

Phonegap: An amazing combination of HTML5, CSS3 and Javascript

Phonegap (Cordova) = HTML5 + CSS3 + Javascript

What a great combination!! How easy is Phonegap to learn!!! A great enhancement in mobile technology....

If you are an iPhone developer, you use Objective C....if Android or Blackberry, you use Java...But is there any technology which can make applications for each platform? Phonegap gives the answer..

Lets discuss what features Phonegap possesses?

Features of Phonegap:

1. PhoneGap is an open source framework.

2. Phonegap supports all the mobile platforms like Apple iOS, Google Android, HP WebOS, RIM BlackBerry, MS Windows Phone, Nokia Symbian OS and Samsung bada.

3. Phonegap supports many mobile hardware features like Accelerometer, Camera, Capture, Compass, Connection, Contacts, Device, Events, File, Geolocation,
Media,Notification (Vibration, Sound, Alert), Storage etc.

4. Phonegap is easy to learn as you only have to learn HTML5, CSS3 and Javascript which I think every developer would be knowing. Just you have to learn the framework
which you can learn within half a month.

5. There are a lot of IDEs which support phonegap framework like CS5.5, Eclipse, XCode etc.

History:

Lets go back in history how phonegap took birth? Idea of developing Phonegap came in iPhoneDevCamp event in San Fransisco because there were less developers who knew Objective C for iPhone as compared to web developers which were expert in web development. Nitobi first created the Phonegap and then Adobe bought Nitobi in October 2011. Phonegap is currently supported by Apache Software Foundation (ASW). When phonegap was developed, it was called Apache Callback but now it has been renamed to Apache Cordova.

Further readings: I am creating a mobile app for blackberry and android using phonegap. I am learning a lot from there. While delvelopment, I am facing a lot of challenges. I will keep you updated with all the information which I get or learn. For now, you can refer Phonegap Official Website.

Delphi 2010, Delphi XE and XE2: A comparison of features

Delphi 2010 vs older versions

Delphi 2010 Release Date: August 25, 2009

Delphi 2010 witnessed a lot of improvements and new features as compared to its older versions. Some of features are listed below:
 
1. Delphi 2010 included a new compiler run-time type information (RTTI) system
2. Support for Windows 7 direct 2D
3. Touch screen and gestures
4. Source code formatter
5. Debugger visualizers
6. Option to also have the old style component palette in the IDE

Note:  Because of the use of Unicode as the default string type, Windows 98, 95, and ME will not run applications produced with Delphi 2009 or later. These operating systems do not support Unicode strings, and Microsoft has dropped support for them. Applications built with Delphi XE2, XE, 2010 and 2009 and VCL will run on Windows 2000 or later.

Comparison between Delphi 2010 and Delphi XE

Delphi XE Release Date: August 30, 2010

Only few enhancements were done in Delphi XE as compared to Delphi 2010. Thats why Delphi XE did not gain much success. Some of the enhancements are listed below:

1. Some IDE fixes were done in Delphi XE which made the IDE faster
2. Some additional third party tools were added in Delphi XE to enhance the capabilities of Delphi
3. No support for Win64 platform in both of them
4. No Mac OSX support in both of them

Comparison between Delphi XE and Delphi XE2

Delphi XE2 Release Date: September 1, 2011

Very much successful release of Embarcadero. Delphi XE2 coexists nicely with earlier versions of RAD Studio, C++Builder and Delphi. A lot of industries and migrating to Delphi XE2 because of its exciting features:

1. Delphi XE2 supports Win64 native development which will make your application faster
2. Delphi XE2 supports Mac OSX native development
3. Delphi XE2 is supplied with both the VCL, and an alternative library called FireMonkey that supports Windows, Apple Mac OS X and the Apple iPhone, iPod Touch and iPad
portable devices.
4. New naming scheme for the units
5. ODBC dbExpress driver support
6. Extensions to the REST support layer
7. Improved Cloud support
8. Improved RTTI (run-time type information)
9. Cross platform support
10. Little migration issues encountered
11. The DataSnap Mobile Connector feature: The DataSnap Mobile Connector feature generates connectivity code that you can incorporate into mobile applications for iOS,
Android, Blackberry and Windows Phone 7. You develop your mobile applications using the standard development tools and languages for each platform such as Objective C with the Xcode IDE for iOS, Java for Android and Blackberry, or Silverlight for Windows Phone 7. You then use the DataSnap Mobile Connector code to provide connectivity to your native C++Builder or Delphi DataSnap server. You can create a single application and deploy to 32-bit Windows, 64-bit Windows and Mac OS X. To create an iOS application, you create a separate project type that is exported and built with Xcode.

Difference in Delphi XE2 Professional and Enterprise Edition:

Delphi XE2 Enterprise Edition contains some extra features which are not present in Delphi XE2 Professiona Edition like:

1. Datasnap
2. DBExpress Driver Support for OSX, Firebird, Oracle, MSSQL, Informix
3. Advanced UML and Code Analysis Tools
4. FinalBuilder

Limitations of Delphi XE2:

1. Applications for 64-bit platforms can be compiled, but not tested or run, on the 32-bit platform.
2. FireMonkey and VCL are not compatible, one or the other must be used, and older VCL applications cannot use Firemonkey unless user interfaces are recreated with
FireMonkey forms and controls.
3. Applications built with Delphi XE2 and FireMonkey will run on Windows XP and later.
4. Delphi XE2 uses the MSBuild system for the build engine, and thus requires a new project file if you are upgrading from version 2007 or earlier. However, the IDE will
seamlessly update your projects to the new format.

Waiting for Delphi XE3 which may out in a month or two......

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.