Abandon d'une boucle

Résolu
PValentin Messages postés 9 Date d'inscription jeudi 28 novembre 2019 Statut Membre Dernière intervention 14 février 2021 - 13 févr. 2021 à 15:03
 PValentin69 - 23 févr. 2021 à 09:24
Bonjour,
Dans l'application que je suis en train de faire, j'ai une form dans laquelle j'affiche 104 images et 104 labels extraits de ma base de données Access (boucle : while not ADOTable1.Eof do).
Grâce à Yanb et Japee (en novembre 2019), ça fonctionne parfaitement.
Depuis, j'ai amélioré cet affichage. En effet, ma base possédant pour l'instant plusieurs centaines d'enregistrement et étant susceptible d'en contenir des milliers, j'ai inséré plusieurs conditions pour déterminer si la page (la form) contient moins de 104 images, 104 images exactement ou un multiple de 104, ou plus de 104 ou d'un multiple de 104.
Si c'est moins de 104 ou exactement 104, la procédure s'arrête là. Si c'est plus de 104 ou 208 ou 312, etc., la procédure affiche un bouton nommé 'suite' et attends (Application.ProcessMessages). Dans les variables déclarées dans ma form, j'ai une variable de type Boolean nommée 'suite', cette variable est initialisée à false et elle prend la valeur true à l'appui sur le bouton 'suite'.
La procédure poursuit alors sa boucle, elle vide toutes les Images et les Labels et affiche les 104 suivants, s'il y en a.
Tout ça fonctionne parfaitement.
Mais voilà : j'ai eu l'idée d'améliorer encore. Lorsque je fais un double-clic sur une image, une nouvelle fiche s'ouvre avec toutes les données relatives à l'mage cliquée. Ça fonctionne si il y a moins de 104 images ou 104 exactement, puisque la boucle de la form d'origine est arrivée à son terme.
Par contre, si la base contient plus de 104 enregistrements, ça ne fonctionne plus.
Ce que je voudrais tester dans un premier temps, c'est de pouvoir stopper la boucle quand je fais un double-clic sur une image, sachant qu'à ce moment là, je ne suis plus dans la procédure qui a lancé cette boucle. Je cherche en vain depuis des jours mais sans résultat.
Si quelqu'un peut m'aider, je lui en serai très reconnaissant, c'est le seul point qui reste en suspend.
Désolé pour la longueur du message !

10 réponses

papyvore Messages postés 223 Date d'inscription samedi 15 novembre 2003 Statut Membre Dernière intervention 16 décembre 2021 15
17 févr. 2021 à 09:57
salut
sans voir ton code c'est pas facile avec toutes ces explications!!! , avec un boolean dans le ondblclick du composant ?
1
cs_yanb Messages postés 271 Date d'inscription lundi 27 octobre 2003 Statut Membre Dernière intervention 7 juillet 2022 14
Modifié le 19 févr. 2021 à 13:43
Salut,

Il y a plusieurs choses qui ne vont pas, mais je pense surtout qu'il y a un problème dans la réflexion de départ...
La boucle ProcessMessages est dans la boucle des impaires, en plus elle bloque l'application si pas "suite".
Quand le chargement des données est long on utilise un "Thread" mais pas utile ici...
Je pencherai plus pour le chargement de la page 1 dans le OnCreate de la form et ensuite faire une gestion des pages et de la mise jour avec 2 boutons + -.
Pour les nombres paires impaires on utilise aussi "Odd"
Pour l'incrémentation il existe aussi "Inc" et "Dec", mais j'ai tendance à utiliser i:=i+1...
Il serait intéressant ensuite d'utiliser une requête SQL pour n'utiliser que ce que l'on a besoin au changement de page, mais au vue de la base pas intéressant me semble-t-il.

Pas testé, donc à modifier ou rectifier pour que ça fonctionne correctement.
...
Button4: TButton;
Button5: TButton;
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure LoadPage(IndexPage: Integer);
...
var
  Form8: TForm8;
  Suite: Boolean;
  NumPage: Integer; 
...
procedure TForm8.FormActivate(Sender: TObject);
begin
  //Rien
end;

//procedure pour charger en fonction du numéro de page
procedure TForm8.LoadPage(IndexPage: Integer);
var
  I: Integer;
  MyLabel: TLabel;
  MyImage: TImage;
begin
  if not ADOTable1.Active then
    ADOTable1.Active := True;
  vide;
  Suite := False;
  Form8.Caption := 'Page n° ' + inttostr(NumPage);  
  ADOTable1.First;
  ADOTable1.MoveBy((104*(IndexPage-1))+1);//On se déplace au début des données que l'on a besoin
  for I := 1 to 104 do
  begin
    //Ce que tu as essayé pour stopper
    Application.ProcessMessages;
    if Suite then
      Break;
    Button1.Visible := False;
    MyLabel := TLabel(FindComponent(Format('Label%d', [I])));
    if MyLabel <> nil then
      MyLabel.Caption := ADOTable1.Fields[0].AsString + ' N° ' + ADOTable1.Fields[5].AsString;
    MyImage := TImage(FindComponent(Format('Image%d', [I])));
    if MyImage <> nil then
    begin
      MyImage.Width := 105;
      MyImage.Height := 105;
      MyImage.picture.Assign(ADOTable1.Fields[1]);
      MyImage.Tag := ADOTable1.Fields[4].AsInteger;
    end;
    if ADOTable1.Eof then
      Break;
    ADOTable1.Next;
  end;
end;

//Bouton page plus
procedure TForm8.Button4Click(Sender: TObject);
begin
  //On regarde si le nombre de données est suffisant pour une nouvelle page
  if ADOTable1.RecordCount > NumPage * 104 then
  begin
    Inc(NumPage);//ou Inc(NumPage,1) ou NumPage := Numpage +1;
    Button4.Caption := Format('Page %d',[NumPage +1]);
    Button5.Caption := Format('Page %d',[NumPage +1]);
    LoadPage(NumPage);//Chargement en fonction numéro de page
  end;
end;

//Bouton page moins
procedure TForm8.Button5Click(Sender: TObject);
begin
  if NumPage> 1 then
  begin
    Dec(NumPage);
    Button4.Caption := Format('Page %d',[NumPage -1]);
    Button5.Caption := Format('Page %d',[NumPage -1]);
    LoadPage(NumPage);
  end;
end;

procedure TForm8.FormCreate(Sender: TObject);
var
  Chemin: string;
begin
  Chemin := ExtractFilePath(Application.ExeName);
  ADOConnection1.Close;
  ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
    'User ID=Admin;' + 'Data Source=' + Chemin + 'Placo.mdb;' +
    'Mode=ReadWrite;' + 'Jet OLEDB:System database="";' +
    'Jet OLEDB:Registry Path="";' + 'Jet OLEDB:Database Password="";' +
    'Jet OLEDB:Engine Type=5;' + 'Jet OLEDB:Database Locking Mode=1;' +
    'Jet OLEDB:Global Partial Bulk Ops=2;' +
    'Jet OLEDB:Global Bulk Transactions=1;' +
    'Jet OLEDB:New Database Password="";' +
    'Jet OLEDB:Create System Database=False;' +
    'Jet OLEDB:Encrypt Database=False;' +
    'Jet OLEDB:Don''t Copy Locale on Compact=False;' +
    'Jet OLEDB:Compact Without Replica Repair=False;' + 'Jet OLEDB:SFP=False;';
  ADOConnection1.Open();
  ADOTable1.Active := True;
  NumPage := 1;
  Button4.Caption := Format('Page %d',[2]);
  Button5.Caption := Format('Page %d',[0]);
  LoadPage(NumPage);
end;
@+
1
PValentin Messages postés 9 Date d'inscription jeudi 28 novembre 2019 Statut Membre Dernière intervention 14 février 2021
14 févr. 2021 à 08:49
Bonjour,
J'ai tenté la chose suivante : faire un 'break' dans ma boucle si le double-clic est détecté sur une des images.

Problème : je n'arrive pas à trouver le bon code, du genre si l'image(n°) est double-cliquée, faire un break.

Si quelqu'un peut m'aider, au moins pour cette action, je testerai dans mon programme.

Merci d'avance.
0
Personne pour me dire comment on fait pour détecter si un composant quelconque est double cliqué ?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Bonjour Papyvore,
Merci d'avoir pris le temps de lire et de répondre.
J'ai hésité à mettre mon code parce qu'il est très long et que étant débutant, j'ai bien peur qu'il ne soit pas très "catholique" !
Le voici quand même :

1) La form qui affiche mes 104 images et labels :

unit Photos;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.StdCtrls,
  Vcl.ExtCtrls, Vcl.Buttons, Printers;

type
  TForm8 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    Image10: TImage;
    Image11: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    Image17: TImage;
    Image18: TImage;
    Image19: TImage;
    Image20: TImage;
    Image21: TImage;
    Image22: TImage;
    Image23: TImage;
    Image24: TImage;
    Image25: TImage;
    Image26: TImage;
    Image27: TImage;
    Image28: TImage;
    Image29: TImage;
    Image30: TImage;
    Image31: TImage;
    Image32: TImage;
    Image33: TImage;
    Image34: TImage;
    Image35: TImage;
    Image36: TImage;
    Image37: TImage;
    Image38: TImage;
    Image39: TImage;
    Image40: TImage;
    Image41: TImage;
    Image42: TImage;
    Image43: TImage;
    Image44: TImage;
    Image45: TImage;
    Image46: TImage;
    Image47: TImage;
    Image48: TImage;
    Image49: TImage;
    Image50: TImage;
    Image51: TImage;
    Image52: TImage;
    Image53: TImage;
    Image54: TImage;
    Image55: TImage;
    Image56: TImage;
    Image57: TImage;
    Image58: TImage;
    Image59: TImage;
    Image60: TImage;
    Image61: TImage;
    Image62: TImage;
    Image63: TImage;
    Image64: TImage;
    Image65: TImage;
    Image66: TImage;
    Image67: TImage;
    Image68: TImage;
    Image69: TImage;
    Image70: TImage;
    Image71: TImage;
    Image72: TImage;
    Image73: TImage;
    Image74: TImage;
    Image75: TImage;
    Image76: TImage;
    Image77: TImage;
    Image78: TImage;
    Image79: TImage;
    Image80: TImage;
    Image81: TImage;
    Image82: TImage;
    Image83: TImage;
    Image84: TImage;
    Image85: TImage;
    Image86: TImage;
    Image87: TImage;
    Image88: TImage;
    Image89: TImage;
    Image90: TImage;
    Image91: TImage;
    Image92: TImage;
    Image93: TImage;
    Image94: TImage;
    Image95: TImage;
    Image96: TImage;
    Image97: TImage;
    Image98: TImage;
    Image99: TImage;
    Image100: TImage;
    Image101: TImage;
    Image102: TImage;
    Image103: TImage;
    Image104: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    ADOTable1Choix2: TWideStringField;
    ADOTable1Photo: TBlobField;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Label41: TLabel;
    Label42: TLabel;
    Label43: TLabel;
    Label44: TLabel;
    Label45: TLabel;
    Label46: TLabel;
    Label47: TLabel;
    Label48: TLabel;
    Label49: TLabel;
    Label50: TLabel;
    Label51: TLabel;
    Label52: TLabel;
    Label53: TLabel;
    Label54: TLabel;
    Label55: TLabel;
    Label56: TLabel;
    Label57: TLabel;
    Label58: TLabel;
    Label59: TLabel;
    Label60: TLabel;
    Label61: TLabel;
    Label62: TLabel;
    Label63: TLabel;
    Label64: TLabel;
    Label65: TLabel;
    Label66: TLabel;
    Label67: TLabel;
    Label68: TLabel;
    Label69: TLabel;
    Label70: TLabel;
    Label71: TLabel;
    Label72: TLabel;
    Label73: TLabel;
    Label74: TLabel;
    Label75: TLabel;
    Label76: TLabel;
    Label77: TLabel;
    Label78: TLabel;
    Label79: TLabel;
    Label80: TLabel;
    Label81: TLabel;
    Label82: TLabel;
    Label83: TLabel;
    Label84: TLabel;
    Label85: TLabel;
    Label86: TLabel;
    Label87: TLabel;
    Label88: TLabel;
    Label89: TLabel;
    Label90: TLabel;
    Label91: TLabel;
    Label92: TLabel;
    Label93: TLabel;
    Label94: TLabel;
    Label95: TLabel;
    Label96: TLabel;
    Label97: TLabel;
    Label98: TLabel;
    Label99: TLabel;
    Label100: TLabel;
    Label101: TLabel;
    Label102: TLabel;
    Label103: TLabel;
    Label104: TLabel;
    Button1: TButton;
    ADOTable1Commencepar: TWideStringField;
    ADOTable1Catégorie: TWideStringField;
    Button2: TButton;
    PrinterSetupDialog1: TPrinterSetupDialog;
    ADOTable1Clé: TAutoIncField;
    ADOTable1Numéro: TWideStringField;
    Button3: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure vide();
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Image1DblClick(Sender: TObject);

  private
    { Déclarations privées }

  public
    { Déclarations publiques }

  end;

var
  Form8: TForm8;
  Suite: Boolean;

implementation

{$R *.dfm}

uses
  Fiche,Liste;

procedure TForm8.vide();
var
  MonImage: TImage;
  MonLabel: TLabel;
  j: Integer;
begin
  with Form8 do
  begin
    for j := 1 to 104 do
    begin
      MonLabel := TLabel(FindComponent(Format('Label%d', [j])));
      MonLabel.Caption := '';
      MonImage := TImage(FindComponent(Format('Image%d', [j])));
      MonImage.picture := nil;
    end;
  end;
end;

procedure TForm8.Button1Click(Sender: TObject);
begin
  Suite := True;
end;

procedure TForm8.Button2Click(Sender: TObject);
begin
  PrinterSetupDialog1.Execute;
  with Printer do
  begin
    Orientation := poLandScape;
    PrintScale := poPrintToFit;
    Form8.Print;
  end;
end;

procedure TForm8.Button3Click(Sender: TObject);
begin
  ADOTable1.Close;
  Form8.Close;
end;

procedure TForm8.FormActivate(Sender: TObject);
var
  i, k, NumCp, NumPage : Integer;
  MyImage: TImage;
  MyLabel: TLabel;
begin
  if ADOTable1.Active=False then
  ADOTable1.Active := True;
  vide;
  ADOTable1.First;
 end;
    NumPage := 1;
    i := 0;
  while not ADOTable1.Eof do
  { -------------------- Début de la boucle ------------------------------ }
  begin
    Suite := False;
    NumCp := NumCp + 1;
    if NumCp = 104 then
      i := 1;
    if (NumCp > 104) and (NumCp < 208) then
      i := 2;
    if NumCp = 208 then
      i := 3;
    if (NumCp > 208) and (NumCp < 312) then
      i := 4;
    if NumCp = 312 then
      i := 5;
    if (NumCp > 312) and (NumCp < 416) then
      i := 6;
    if NumCp = 416 then
      i := 7;
    if (NumCp > 416) and (NumCp < 520) then
      i := 8;
    if NumCp = 520 then
      i := 9;
    if (NumCp > 520) and (NumCp < 624) then
      i := 10;
    if NumCp = 624 then
      i := 11;
    { ====== A poursuivre en fonction du nombre de pages à afficher ====== }
    Form8.Caption := 'Page n° ' + inttostr(NumPage);
    if i = 0 then { -------------------- i = 0 --------------------------- }
    begin
      Button1.Visible := False;
      MyLabel := TLabel(FindComponent(Format('Label%d', [NumCp])));
      MyImage := TImage(FindComponent(Format('Image%d', [NumCp])));
      if MyLabel <> nil then
        MyLabel.Caption := ADOTable1.Fields[0].AsString + ' N° ' +
          ADOTable1.Fields[5].AsString;
      if MyImage <> nil then
      begin
        MyImage.Width := 105;
        MyImage.Height := 105;
        MyImage.picture.Assign(ADOTable1.Fields[1]);
        MyImage.Tag := ADOTable1.Fields[4].AsInteger;
      end;
    end;
    if (i <> 0) AND (i mod 2 = 0) then { ---------- i = 2,4,6,8 ---------- }
    begin
      Button1.Visible := False;
      MyLabel := TLabel(FindComponent(Format('Label%d',
        [NumCp - (NumPage - 1) * 104])));
      MyImage := TImage(FindComponent(Format('Image%d',
        [NumCp - (NumPage - 1) * 104])));
      if MyLabel <> nil then
        MyLabel.Caption := ADOTable1.Fields[0].AsString + ' N° ' +
          ADOTable1.Fields[5].AsString;
      if MyImage <> nil then
      begin
        MyImage.Width := 105;
        MyImage.Height := 105;
        MyImage.picture.Assign(ADOTable1.Fields[1]);
        MyImage.Tag := ADOTable1.Fields[4].AsInteger;
      end;
    end;
    if i mod 2 = 1 then { --------------- i = 1,3,5,7 --------------------- }
    begin
      Suite := False;
      MyLabel := TLabel(FindComponent(Format('Label%d',
        [NumCp - (NumPage - 1) * 104])));
      MyImage := TImage(FindComponent(Format('Image%d',
        [NumCp - (NumPage - 1) * 104])));
      if MyLabel <> nil then
        MyLabel.Caption := ADOTable1.Fields[0].AsString + ' N° ' +
          ADOTable1.Fields[5].AsString;
      if MyImage <> nil then
      begin
        MyImage.Width := 105;
        MyImage.Height := 105;
        MyImage.picture.Assign(ADOTable1.Fields[1]);
        MyImage.Tag := ADOTable1.Fields[4].AsInteger;
      end;
      Button1.Visible := True;
      Repeat
        Application.ProcessMessages;
      Until Suite;
      NumPage := NumPage + 1;
    end;
    ADOTable1.Next;
  end;
end;

procedure TForm8.FormCreate(Sender: TObject);
var
  Chemin: string;
begin
  Chemin := ExtractFilePath(Application.ExeName);
  ADOConnection1.Close;
  ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
    'User ID=Admin;' + 'Data Source=' + Chemin + 'Placo.mdb;' +
    'Mode=ReadWrite;' + 'Jet OLEDB:System database="";' +
    'Jet OLEDB:Registry Path="";' + 'Jet OLEDB:Database Password="";' +
    'Jet OLEDB:Engine Type=5;' + 'Jet OLEDB:Database Locking Mode=1;' +
    'Jet OLEDB:Global Partial Bulk Ops=2;' +
    'Jet OLEDB:Global Bulk Transactions=1;' +
    'Jet OLEDB:New Database Password="";' +
    'Jet OLEDB:Create System Database=False;' +
    'Jet OLEDB:Encrypt Database=False;' +
    'Jet OLEDB:Don''t Copy Locale on Compact=False;' +
    'Jet OLEDB:Compact Without Replica Repair=False;' + 'Jet OLEDB:SFP=False;';
  ADOConnection1.Open();
  ADOTable1.Active := True;
end;

procedure TForm8.Image1DblClick(Sender: TObject);
var
  NumEnr : Integer;
begin
  NumEnr:=TImage(Sender).Tag;
  Form9.Edit1.Text:=IntToStr(NumEnr);
  Form9.Edit2.Text:='Photos';
end;

end.


2) La form qui affiche les détails de l'image double-cliquée :

unit Fiche;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.StdCtrls,
  Vcl.DBCtrls, Vcl.ExtCtrls, Vcl.Mask, Vcl.Grids, Vcl.DBGrids;

type
  TForm9 = class(TForm)
    Panel1: TPanel;
    DBText2: TDBText;
    DBImage1: TDBImage;
    DBImage2: TDBImage;
    Label2: TLabel;
    Label5: TLabel;
    Panel2: TPanel;
    DBText8: TDBText;
    Label9: TLabel;
    DBText9: TDBText;
    Label10: TLabel;
    DBText10: TDBText;
    Label11: TLabel;
    Panel3: TPanel;
    Label12: TLabel;
    DBText11: TDBText;
    Label13: TLabel;
    Label14: TLabel;
    DBText12: TDBText;
    Label15: TLabel;
    Label16: TLabel;
    DBText13: TDBText;
    Panel4: TPanel;
    DBText14: TDBText;
    Label17: TLabel;
    DBText15: TDBText;
    Label18: TLabel;
    DBText16: TDBText;
    Label19: TLabel;
    Panel5: TPanel;
    Label1: TLabel;
    DBText1: TDBText;
    Label3: TLabel;
    DBText3: TDBText;
    DBText4: TDBText;
    Label4: TLabel;
    DBEdit1: TDBEdit;
    DBText5: TDBText;
    Edit1: TEdit;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    ADOTable1Clé: TIntegerField;
    ADOTable1Pays: TWideStringField;
    ADOTable1Région: TWideStringField;
    ADOTable1Commencepar: TWideStringField;
    ADOTable1Choix2: TWideStringField;
    ADOTable1Catégorie: TWideStringField;
    ADOTable1Numéro: TWideStringField;
    ADOTable1Référence: TWideStringField;
    ADOTable1Page: TIntegerField;
    ADOTable1Titre: TWideStringField;
    ADOTable1TexteDessus: TWideStringField;
    ADOTable1PrixAchat: TBCDField;
    ADOTable1Cote: TBCDField;
    ADOTable1Endouble: TWideStringField;
    ADOTable1Observation: TWideStringField;
    ADOTable1Photo: TBlobField;
    ADOTable1Photo2: TBlobField;
    Edit2: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);

  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form9: TForm9;

implementation

{$R *.dfm}

Uses
  Menu,Photos,Liste;

procedure TForm9.FormClose(Sender: TObject; var Action: TCloseAction);
begin
      Form8.Enabled := true;
      Form8.Show;
end;

procedure TForm9.FormCreate(Sender: TObject);
var
  Chemin: string;
begin
  Chemin := ExtractFilePath(Application.ExeName);
  ADOConnection1.Close;
  ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
    'User ID=Admin;' + 'Data Source=' + Chemin + 'Placo.mdb;' +
    'Mode=ReadWrite;' + 'Jet OLEDB:System database="";' +
    'Jet OLEDB:Registry Path="";' + 'Jet OLEDB:Database Password="";' +
    'Jet OLEDB:Engine Type=5;' + 'Jet OLEDB:Database Locking Mode=1;' +
    'Jet OLEDB:Global Partial Bulk Ops=2;' +
    'Jet OLEDB:Global Bulk Transactions=1;' +
    'Jet OLEDB:New Database Password="";' +
    'Jet OLEDB:Create System Database=False;' +
    'Jet OLEDB:Encrypt Database=False;' +
    'Jet OLEDB:Don''t Copy Locale on Compact=False;' +
    'Jet OLEDB:Compact Without Replica Repair=False;' + 'Jet OLEDB:SFP=False;';
  ADOConnection1.Open();
  ADOTable1.Active := True;
end;

procedure TForm9.FormShow(Sender: TObject);
begin
  ADOTable1.Open;
  ADOTable1.Filtered := False;
  ADOTable1.Filter := 'Clé = ' + Edit1.Text;
  ADOTable1.Filtered := True;
end;

end.


Lorsque je double-clique sur une des images, la form8 se ferme, la form9 s'affiche.
Tant que la form8 n'est pas remplie avec 104 enregistrements, je peux fermer la form9 et revenir sur la form8 et recommencer.
Par contre, si laform8 est pleine, j'affiche bien la form9 mais tout est bloqué, je n'ai plus accès à la form8 et je suis obligé de quitter l'appli.

Je ne sais pas s'il est possible de résoudre ce soucis. Je pense que ça vient du fait que ma boucle while dans OnActivate n'est pas arrivée au bout.

Merci pour vos idées. Je crois que je vais laisser tomber, ça fait des semaines que j'ai essayé un peu tout avant de me décider à poser ma question sur le forum.
0
papyvore Messages postés 223 Date d'inscription samedi 15 novembre 2003 Statut Membre Dernière intervention 16 décembre 2021 15
19 févr. 2021 à 08:47
Wahouuu! pas simple
Mettre un peu d'ordre dans le code.
créer une unit data module dans laquelle tu mets tous
DataSource1: TDataSource;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable et tous les champs.
Faire 1 seule fois ADOConnection1 (et pas dans chaque form) open table1 1 seule fois est close table1 à la fermeture de l'application.
Nommer tes composants label1..2,3 leur donner un nom plus explicite ça permet de mieux s'y retrouver, ainsi que les boutons.
Repeat
Application.ProcessMessages;
Until Suite;
il faut remettre Suite := false après until
Dans procedure TForm8.Image1DblClick(Sender: TObject);
il faut peut être ajouter Form9.show pour le refaire passer par form9.activate.
tester en plaçant des points d'arrêts pour voir où ça bloque.
Bref, ton code semble brouillon ,reprend ton code tu vas trouver .
Tiens nous au courant.

0
Merci papyvore et Yanb.

@Papyvore.
Je me doutais que mon code n'était pas très 'propre', mais pas à ce point. Tout ce que je connais en delphi, je l'ai appris sur le net, en essayant de développer cette application qui me sera très utile. Je me rends compte que c'est beaucoup plus ardu que je le pensais.
En tout cas, merci pour l'unit data module, je ne connaissais pas, et comme mon appli contient 16 'unit', ça va alléger pas mal !

@Yanb.
Effectivement, je m'y suis mal pris dès le début de cette étape de mon appli. Je suis resté coincé dans ma boucle while alors que ta suggestion est claire et me semble maintenant évidente.

Dés que je pourrai modifier mon code et tester tout ça, je vous tiendrai au courant.

Bon week-end

NB : Je crois que si je veux utiliser delphi correctement, il va falloir que je reprenne depuis le début, c'est à dire, acheter un bouquin et apprendre dans l'ordre au lieu d'essayer des modules par ci par là.
A 66 ans, c'est pas gagné !!!!
0
papyvore Messages postés 223 Date d'inscription samedi 15 novembre 2003 Statut Membre Dernière intervention 16 décembre 2021 15
Modifié le 20 févr. 2021 à 11:21
salut
"Je me doutais que mon code n'était pas très 'propre', mais pas à ce point" désolé je voulais pas vexer ,juste un peu de rigueur tu verra ça marchera
pour ton âge t'inquiète pas, pour moi tu fais jeune je pourrais presque être ton père :))
vas voire ici https://www.youtube.com/playlist?list=PLHLdMyq6m8_s-OxVA_qZ4O_YvVgl_1nOp c'est assez intéressent.
des exemples utiles.
https://github.com/DeveloppeurPascal/ApprendreLaProgrammationAvecDelphi

0
Salut papyvore,
Avec ton pseudo, je me doutais que tu avais "un certain âge".
Rassures-toi, je ne suis nullement vexé, au contraire, j'ai soif d'apprendre, surtout dans le domaine de l'informatique. J'ai commencé avec un ZX81 de Sinclair, ça date pas d'hier. Ensuite avec un Oric Atmos. Je programmais en basic.
Et merci pour les liens, je vais regarder ça avec attention.

@+
0
Salut Papyvore et Yanb,

Ça marche !!!!!

Yannb, j'ai testé ton code. Après de petites adaptations, il y avait une grosse amélioration. J'ai procédé à quelques modifications et tout fonctionne à merveille. Il me reste à modifier diverses petites choses, mais cette fois, mon appli est terminée (jusqu'à ce que je trouve quelque chose à ajouter !). Si tu te souviens lors de mon premier message, en novembre 2019, je t'avais expliqué que c'est une application pour gérer ma collection de capsules de champagne, mousseux, cidre, etc. C'est uniquement pour mon usage personnel et c'était aussi pour apprendre d'avantage sur delphi.
Encore un grand merci.

Papyvore, je vais maintenant appliquer ta préconisation du 'unit data module' pour alléger tout ça et relire tous les codes de mes 16 form pour optimiser.
Je suis allé voir les liens que tu m'as transmis, c'est très intéressant.Merci aussi pour ça, et merci pour tes encouragements.

Bonne journée à tous les deux.
0
Rejoignez-nous