Field - usando campos ADT |
Top Previous Next |
// usando campos ADT
///////////// FORM
object Form1: TForm1 Left = 200 Top = 114 Width = 696 Height = 480 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object DBGrid1: TDBGrid Left = 196 Top = 52 Width = 481 Height = 377 DataSource = Ds TabOrder = 0 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -11 TitleFont.Name = 'MS Sans Serif' TitleFont.Style = [] Columns = < item Expanded = False FieldName = 'Cliente' Width = 103 Visible = True end item Expanded = False FieldName = 'Cliente.Codigo' Visible = True end item Expanded = False FieldName = 'Cliente.Nome' Visible = True end> end object Tb: TAClientDataSet Active = True Aggregates = <> FieldDefs = < item Name = 'Cliente' ChildDefs = < item Name = 'Codigo' Attributes = [faReadonly] DataType = ftAutoInc end item Name = 'Nome' DataType = ftString Size = 20 end> DataType = ftADT Size = 2 end> IndexDefs = <> Params = <> StoreDefs = True Left = 112 Top = 164 Data = { 7D0000009619E0BD0200000018000000030000000000030000007D0007436C69 656E746502000C010000000006436F6469676F04000100020001000753554254 5950450200490008004175746F696E6300044E6F6D6501004900000001000557 4944544802000200140001000C4155544F494E4356414C554504000100010000 00} object TbCliente: TADTField FieldName = 'Cliente' OnGetText = TbCLIENTEGetText object TbClienteCodigo: TAutoIncField FieldName = 'Codigo' ReadOnly = True end object TbClienteNome: TStringField FieldName = 'Nome' end end end object Ds: TDataSource DataSet = Tb Left = 152 Top = 164 end end
////////////////// fonte
unit teste21;
interface
uses Forms, DB, DBClient, AClientDataSet, Classes, Controls, Grids, DBGrids;
type TForm1 = class(TForm) Tb: TAClientDataSet; Ds: TDataSource; DBGrid1: TDBGrid; TbCliente: TADTField; TbClienteCodigo: TAutoIncField; TbClienteNome: TStringField; procedure TbCLIENTEGetText(Sender: TField; var Text: String; DisplayText: Boolean); end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.TbCLIENTEGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin Text := TbCLIENTECODIGO.asString + '-' + TbCLIENTENOME.asString end;
end.
{
1. crie no fieldefs: 1.1 um campo do tipo ADT (clientes) 1.2 dentro de cliente.childdef crie mais 2 campos 1. codigo autoinc 2. nome string
2. clique 2x no clientedataset e com botao difeiro selecione Add All fiels
3. coloque todos os campos no grid. se quiser pode deixar ele expandido ou nao, na propriedade EXPANDED da coluna
|