~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to examples/mssql/dbform.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit dbform;
 
2
 
 
3
{$mode objfpc}{$H+}
 
4
 
 
5
interface
 
6
 
 
7
uses
 
8
  Classes, SysUtils,
 
9
  mssqlconn, // mssqlconn was added to 2.6.1, you need a recent 2.6.1
 
10
  db, sqldb, FileUtil, Forms, Controls, Graphics,
 
11
  Dialogs, DBGrids, dbloginform;
 
12
 
 
13
type
 
14
 
 
15
  { TForm1 }
 
16
 
 
17
  TForm1 = class(TForm)
 
18
    Datasource1: TDatasource;
 
19
    DBGrid1: TDBGrid;
 
20
    MSSQLConnection1: TMSSQLConnection;
 
21
    SQLQuery1: TSQLQuery;
 
22
    SQLTransaction1: TSQLTransaction;
 
23
    SybaseConnection1: TSybaseConnection;
 
24
    procedure FormCreate(Sender: TObject);
 
25
  private
 
26
    { private declarations }
 
27
  public
 
28
    { public declarations }
 
29
  end;
 
30
 
 
31
var
 
32
  Form1: TForm1;
 
33
 
 
34
implementation
 
35
 
 
36
{$R *.lfm}
 
37
 
 
38
{ TForm1 }
 
39
 
 
40
 
 
41
procedure TForm1.FormCreate(Sender: TObject);
 
42
type
 
43
  DBType=(MSSQL,SybaseASE);
 
44
var
 
45
  ChosenDB: DBType;
 
46
  Connection: TSQLConnection;
 
47
  DBSelected: string;
 
48
  GoodConnection: boolean;
 
49
  LoginForm: dbloginform.TLoginForm;
 
50
  Password: string;
 
51
  UserCancel: boolean;
 
52
begin
 
53
  // Let user login.
 
54
  GoodConnection:=false;
 
55
  UserCancel:=false;
 
56
  LoginForm:=dbloginform.TLoginForm.Create(Nil);
 
57
  try
 
58
    while (GoodConnection=false) and (UserCancel=false) do
 
59
    begin
 
60
      if LoginForm.ShowModal=mrOK then
 
61
      begin
 
62
        DBSelected:=LoginForm.DatabaseType.Items[LoginForm.DatabaseType.ItemIndex];
 
63
        // Use the text in the databasetype combobox to see what db the user wants.
 
64
        // Then we point our Connection to the relevant TSQLConnection descendant.
 
65
        case UpperCase(DBSelected) of
 
66
        'MS SQL SERVER':
 
67
          begin
 
68
            ChosenDB:=MSSQL;
 
69
            Connection:=MSSQLConnection1;
 
70
          end;
 
71
        'SYBASE ASE':
 
72
          begin
 
73
            ChosenDB:=SybaseASE;
 
74
            Connection:=SybaseConnection1;
 
75
          end
 
76
        else
 
77
          begin
 
78
            showmessage('Unknown database type '+DBSelected+' chosen. Aborting. Pleae fix the code!');
 
79
            Application.Terminate;
 
80
          end;
 
81
        end;
 
82
        if LoginForm.OSAuthentication.Checked then
 
83
        begin
 
84
          // Use operating system credentials - mssqlconn
 
85
          // expectes empty username/password then.
 
86
          Connection.UserName:='';
 
87
          Connection.Password:='';
 
88
        end
 
89
        else
 
90
        begin
 
91
          // Use regular username/password
 
92
          Connection.UserName:=LoginForm.User.Text;
 
93
          Connection.Password:=LoginForm.Password.Text;
 
94
        end;
 
95
        if LoginForm.Port.Text<>'' then
 
96
        begin
 
97
          Connection.HostName:=LoginForm.Server.Text+':'+LoginForm.Port.Text;
 
98
        end
 
99
        else
 
100
        begin
 
101
          // Default/no port. Let the connector sort it out.
 
102
          Connection.HostName:=LoginForm.Server.Text;
 
103
        end;
 
104
        Connection.DatabaseName:=LoginForm.Database.Text;
 
105
 
 
106
        // Actually, this should work both on MS SQL and Sybase server, so no need to change it:
 
107
        //SQLQuery1.SQL.Text:='select * from sysservers';
 
108
        // Everything set up, now connect to database.
 
109
        // First make sure the other connection is switched off:
 
110
        if ChosenDB=MSSQL then
 
111
        begin
 
112
          SybaseConnection1.Connected:=false;
 
113
        end
 
114
        else
 
115
        begin
 
116
          MSSQLConnection1.Connected:=false;
 
117
        end;
 
118
        SQLTransaction1.DataBase:=Connection;
 
119
        SQLQuery1.DataBase:=Connection;
 
120
        try
 
121
          Connection.Connected:=true;
 
122
          GoodConnection:=true;
 
123
        except
 
124
          on E: Exception do
 
125
          begin
 
126
            GoodConnection:=false;
 
127
            showmessage('Error connecting to database. Technical details: '+E.ClassName+'/'+E.Message);
 
128
          end;
 
129
        end;
 
130
      end
 
131
      else
 
132
      begin
 
133
        showmessage('User cancelled login. Stopping.');
 
134
        UserCancel:=true; //Tell the loop to release us.
 
135
        Application.Terminate;
 
136
      end;
 
137
    end;
 
138
    if UserCancel=false then
 
139
    begin
 
140
      // Now activate the components "downstream" of the database connection to get the data
 
141
      // displayed to the user
 
142
      try
 
143
        SQLTransaction1.Active:=true;
 
144
        SQLQuery1.Active:=true;
 
145
        GoodConnection:=true;
 
146
      except
 
147
        on E: Exception do
 
148
        begin
 
149
          GoodConnection:=false;
 
150
          showmessage('Error connecting to database. Technical details: '+E.ClassName+'/'+E.Message);
 
151
        end;
 
152
      end;
 
153
    end;
 
154
  finally
 
155
    // Close the form and release memory
 
156
    LoginForm.Release;
 
157
  end;
 
158
end;
 
159
 
 
160
end.
 
161