Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 6

Chapter 14 - Project AdtDemo

Project Structure

AdtDemo.dpr
program AdtDemo;

uses
  Forms,
  AdtForm in 'AdtForm.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
AdtForm.pas
unit AdtForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBClient, Grids, DBGrids, MidasLib;

type
  TForm1 = class(TForm)
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    ClientDataSet1ID: TIntegerField;
    ClientDataSet1Name: TADTField;
    ClientDataSet1NameLastName: TStringField;
    ClientDataSet1NameFirstName: TStringField;
    procedure ClientDataSet1NameGetText(Sender: TField; var Text: String;
      DisplayText: Boolean);
    procedure DBGrid1TitleClick(Column: TColumn);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ClientDataSet1NameGetText(Sender: TField;
  var Text: String; DisplayText: Boolean);
begin
  Text := ClientDataSet1NameFirstName.AsString + ' ' +
    ClientDataSet1NameLastName.AsString;
end;

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
  if Column.Field.FullName = 'Name' then
    ClientDataSet1.IndexFieldNames := 'Name.LastName'
  else
    ClientDataSet1.IndexFieldNames := Column.Field.FullName;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ClientDataSet1.LogChanges := False;
end;

end.
AdtForm.dfm
object Form1: TForm1
  Left = 340
  Top = 134
  Width = 398
  Height = 212
  Caption = 'AdtDemo'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object DBGrid1: TDBGrid
    Left = 0
    Top = 0
    Width = 390
    Height = 185
    Align = alClient
    DataSource = DataSource1
    Options = [dgEditing, dgTitles, dgIndicator, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit]
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
    OnTitleClick = DBGrid1TitleClick
    Columns = <
      item
        Expanded = False
        FieldName = 'ID'
        Visible = True
      end
      item
        FieldName = 'Name'
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'Name.LastName'
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'Name.FirstName'
        Width = 167
        Visible = True
      end>
  end
  object ClientDataSet1: TClientDataSet
    Active = True
    Aggregates = <>
    FileName = 'C:\md6code\14\AdtDemo\data.cds'
    FieldDefs = <
      item
        Name = 'ID'
        DataType = ftInteger
      end
      item
        Name = 'Name'
        ChildDefs = <
          item
            Name = 'LastName'
            DataType = ftString
            Size = 20
          end
          item
            Name = 'FirstName'
            DataType = ftString
            Size = 20
          end>
        DataType = ftADT
        Size = 2
      end>
    IndexDefs = <
      item
        Name = 'Index'
        Fields = 'Name.LastName'
      end>
    Params = <>
    StoreDefs = True
    Left = 32
    Top = 24
    Data = {
      610100009619E0BD020000001800000004000700000003000000E00002494404
      00010000000000044E616D6502000C0100000000084C6173744E616D65010049
      00000001000557494454480200020014000946697273744E616D650100490000
      00010005574944544802000200140002000A4348414E47455F4C4F4704008200
      1200000001000000000000000400000002000000000000000400000003000000
      0000000004000000040000000000000004000000050000000100000008000000
      0600000005000000080000000D44454641554C545F4F52444552020082000100
      000003000508010000000543616E74F9054D6172636F04080200000005536D69
      7468044A6F686E040803000000084D63446F6E616C64045061756C0408050000
      0007426F726C616E64054672616E6B0D08010000000543616E74F9064D617263
      6F640C08010000000543616E74F9054D6172636F000804000000054761746573
      0442696C6C}
    object ClientDataSet1ID: TIntegerField
      FieldName = 'ID'
    end
    object ClientDataSet1Name: TADTField
      FieldName = 'Name'
      OnGetText = ClientDataSet1NameGetText
      object ClientDataSet1NameLastName: TStringField
        FieldName = 'LastName'
      end
      object ClientDataSet1NameFirstName: TStringField
        FieldName = 'FirstName'
      end
    end
  end
  object DataSource1: TDataSource
    DataSet = ClientDataSet1
    Left = 32
    Top = 80
  end
end