Lister une table

cs_Metrox Messages postés 267 Date d'inscription jeudi 19 septembre 2002 Statut Membre Dernière intervention 8 septembre 2013 - 25 juil. 2003 à 10:56
sablor Messages postés 58 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 1 octobre 2004 - 25 juil. 2003 à 15:47
'lut all,
j'aimerais savoir s'il existe une commande qui permette de lister une table...j'explique: j'aimerais que cette commande exécute une requête, et qu'elle m'affiche tous les enregistrements l'un à la suite de l'autre, sans bouton suivant!

Quelqu'un saurait m'aider???

Merci!

M@x ---> Go on www.metrox.be

4 réponses

sablor Messages postés 58 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 1 octobre 2004
25 juil. 2003 à 11:45
Salut a toi tout seul

Bon voici une solution pour ton probleme

Utilise un TDBGrid.
Pour cela tu as besoin d'un TTable ou d'un TQuery d'1 TDataSource et d'un TDBGrid...

Tu specifie ta table, tu branche ta table avec ta TDataSource et ensuite tu indiques a ton TDBGrid qu'il doit recuperer les info dans le TDataSource...

Et voila... OK???

A+
Sablor
0
cs_Metrox Messages postés 267 Date d'inscription jeudi 19 septembre 2002 Statut Membre Dernière intervention 8 septembre 2013
25 juil. 2003 à 13:14
Je comprends pas pk, sa marche pas :-( :-(
T'aurais pas une adresse mail pour que je puisse t'envoyer ma source, et que tu jettes un coup d'oeil?

M@x ---> Go on www.metrox.be
0
sablor Messages postés 58 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 1 octobre 2004
25 juil. 2003 à 15:46
Bon voici un exemple

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Mask, DBCtrls, Db, Grids, DBGrids, DBTables;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Table1: TTable;
        Table1ID_PERSONNE: TAutoIncField;
        Table1NOM_PERS: TStringField;
        Table1PRENOM_PERS: TStringField;
        Table1AGE: TIntegerField;
        Table1TAILLE: TIntegerField;
        Table1POIDS: TIntegerField;
    Label1: TLabel;
    DBEdit1: TDBEdit;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    Label3: TLabel;
    DBEdit3: TDBEdit;
    Label4: TLabel;
    DBEdit4: TDBEdit;
    Label5: TLabel;
    DBEdit5: TDBEdit;
    Label6: TLabel;
    DBEdit6: TDBEdit;
    cmdValider: TBitBtn;
    cmdAnnuler: TBitBtn;
    cmdConnection: TBitBtn;
    cmdAjouter: TBitBtn;
    cmdModifier: TBitBtn;
    cmdSupprimer: TBitBtn;
    procedure cmdConnectionClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure cmdAjouterClick(Sender: TObject);
    procedure cmdModifierClick(Sender: TObject);
    procedure cmdSupprimerClick(Sender: TObject);
    procedure cmdValiderClick(Sender: TObject);
    procedure cmdAnnulerClick(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
    procedure GstInterface;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Table1.Active then Table1.Close;
end;

procedure TForm1.gstInterface;
var bAction : boolean;
beginbAction :((Table1.State dsEdit) or (Table1.State = dsInsert));
    cmdAjouter.Enabled := not bAction;
    cmdModifier.Enabled := not bAction;
    cmdSupprimer.Enabled := not bAction;
    cmdValider.Visible := bAction;
    cmdAnnuler.Visible := bAction;

    DBEdit1.Enabled := bAction;
    DBEdit2.Enabled := bAction;
    DBEdit3.Enabled := bAction;
    DBEdit4.Enabled := bAction;
    DBEdit5.Enabled := bAction;
    DBEdit6.Enabled := bAction;
end;

procedure TForm1.cmdConnectionClick(Sender: TObject);
var bActive : Boolean;
begin
cmdConnection.Enabled := False;
    bActive := Table1.Active;
    Table1.Active := not(bActive);
    bActive := Table1.Active;
if bActive then cmdConnection.Caption := 'Deconnection'
    else cmdConnection.Caption := 'Connection';
    cmdAjouter.Enabled := bActive;
    cmdModifier.Enabled := bActive;
    cmdSupprimer.Enabled := bActive;
    cmdConnection.Enabled := True;
end;

procedure TForm1.cmdAjouterClick(Sender: TObject);
begin
Table1.Insert;
    gstInterface;
end;

procedure TForm1.cmdModifierClick(Sender: TObject);
begin
Table1.Edit;
    gstInterface;
end;

procedure TForm1.cmdSupprimerClick(Sender: TObject);
begin
Table1.Delete;
    gstInterface;
end;

procedure TForm1.cmdValiderClick(Sender: TObject);
begin
Table1.Post;
    gstInterface;
end;

procedure TForm1.cmdAnnulerClick(Sender: TObject);
begin
Table1.Cancel;
    gstInterface;
end;

end.


Sablor
0
sablor Messages postés 58 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 1 octobre 2004
25 juil. 2003 à 15:47
et tu as besoin de mettre le code suivant dans un .dfm

object Form1: TForm1
  Left = 390
  Top = 112
  Width = 713
  Height = 332
  Caption = 'Form1'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 392
    Top = 8
    Width = 77
    Height = 13
    Caption = 'ID_PERSONNE'
    FocusControl = DBEdit1
  end
  object Label2: TLabel
    Left = 392
    Top = 48
    Width = 60
    Height = 13
    Caption = 'NOM_PERS'
    FocusControl = DBEdit2
  end
  object Label3: TLabel
    Left = 392
    Top = 88
    Width = 82
    Height = 13
    Caption = 'PRENOM_PERS'
    FocusControl = DBEdit3
  end
  object Label4: TLabel
    Left = 392
    Top = 128
    Width = 22
    Height = 13
    Caption = 'AGE'
    FocusControl = DBEdit4
  end
  object Label5: TLabel
    Left = 480
    Top = 128
    Width = 36
    Height = 13
    Caption = 'TAILLE'
    FocusControl = DBEdit5
  end
  object Label6: TLabel
    Left = 568
    Top = 128
    Width = 33
    Height = 13
    Caption = 'POIDS'
    FocusControl = DBEdit6
  end
  object DBGrid1: TDBGrid
    Left = 8
    Top = 8
    Width = 377
    Height = 289
    DataSource = DataSource1
    Options = [dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete, dgCancelOnExit]
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
  end
  object DBEdit1: TDBEdit
    Left = 392
    Top = 24
    Width = 64
    Height = 21
    DataField = 'ID_PERSONNE'
    DataSource = DataSource1
    Enabled = False
    TabOrder = 1
  end
  object DBEdit2: TDBEdit
    Left = 392
    Top = 64
    Width = 304
    Height = 21
    DataField = 'NOM_PERS'
    DataSource = DataSource1
    Enabled = False
    TabOrder = 2
  end
  object DBEdit3: TDBEdit
    Left = 392
    Top = 104
    Width = 304
    Height = 21
    DataField = 'PRENOM_PERS'
    DataSource = DataSource1
    Enabled = False
    TabOrder = 3
  end
  object DBEdit4: TDBEdit
    Left = 392
    Top = 144
    Width = 64
    Height = 21
    DataField = 'AGE'
    DataSource = DataSource1
    Enabled = False
    TabOrder = 4
  end
  object DBEdit5: TDBEdit
    Left = 480
    Top = 144
    Width = 64
    Height = 21
    DataField = 'TAILLE'
    DataSource = DataSource1
    Enabled = False
    TabOrder = 5
  end
  object DBEdit6: TDBEdit
    Left = 568
    Top = 144
    Width = 64
    Height = 21
    DataField = 'POIDS'
    DataSource = DataSource1
    Enabled = False
    TabOrder = 6
  end
  object cmdValider: TBitBtn
    Left = 392
    Top = 208
    Width = 89
    Height = 32
    Caption = 'Valider'
    TabOrder = 7
    Visible = False
    OnClick = cmdValiderClick
  end
  object cmdAnnuler: TBitBtn
    Left = 480
    Top = 208
    Width = 89
    Height = 32
    Caption = 'Annuler'
    TabOrder = 8
    Visible = False
    OnClick = cmdAnnulerClick
  end
  object cmdConnection: TBitBtn
    Left = 568
    Top = 208
    Width = 89
    Height = 32
    Caption = 'Connection'
    TabOrder = 9
    OnClick = cmdConnectionClick
  end
  object cmdAjouter: TBitBtn
    Left = 392
    Top = 176
    Width = 89
    Height = 32
    Caption = 'Ajouter'
    Enabled = False
    TabOrder = 10
    OnClick = cmdAjouterClick
  end
  object cmdModifier: TBitBtn
    Left = 480
    Top = 176
    Width = 89
    Height = 32
    Caption = 'Modifier'
    Enabled = False
    TabOrder = 11
    OnClick = cmdModifierClick
  end
  object cmdSupprimer: TBitBtn
    Left = 568
    Top = 176
    Width = 89
    Height = 32
    Caption = 'Supprimer'
    Enabled = False
    TabOrder = 12
    OnClick = cmdSupprimerClick
  end
  object Table1: TTable
    DatabaseName = 'DELPHIFR'
    TableName = 'PERSONNE.db'
    Left = 328
    Top = 24
    object Table1ID_PERSONNE: TAutoIncField
      FieldName = 'ID_PERSONNE'
    end
    object Table1NOM_PERS: TStringField
      FieldName = 'NOM_PERS'
      Size = 50
    end
    object Table1PRENOM_PERS: TStringField
      FieldName = 'PRENOM_PERS'
      Size = 50
    end
    object Table1AGE: TIntegerField
      FieldName = 'AGE'
    end
    object Table1TAILLE: TIntegerField
      FieldName = 'TAILLE'
    end
    object Table1POIDS: TIntegerField
      FieldName = 'POIDS'
    end
  end
  object DataSource1: TDataSource
    DataSet = Table1
    Left = 328
    Top = 88
  end
end

Sablor
0
Rejoignez-nous