dbgrid and dbf lazarus / 31-LCL ---------------------------------------------------------------------- Fabius · 2021-06-01 16:17 Hello everyone, thanks for reading me, lol I'm from France, I speak poor English, sorry I have the following problem I have a dbgrid which linked to a Dbase table, by Dbf and datasource I fill in the DBF by an import procedure from a bank OFX the content of the DBF appears correctly in the dbgrid, but when i click the elevator or browse the dbgrid, all records become the same Where do you think it came from, a bug, bad programming? Thank you for your answers cordially ---------------------------------------------------------------------- Fabius · 2021-06-01 16:23 photo ---------------------------------------------------------------------- Handoko · 2021-06-01 16:29 Hello Fabius, Welcome to the forum. I wrote a small stock control program for used in a small shop, using TDBF, TDBGrid and many other components. The program was written using Lazarus 0.9.26, many years have passed so far no complain from the user. So I believe, you must have done something wrong. We need more information. It would be better if you can provide a compile-able source code. If you are not willing to publicize the project, you can write a short demo that can show us the issue. Your English is good. Very clear and understandable. ---------------------------------------------------------------------- Fabius · 2021-06-02 07:37 Hello, thank you for the reply I have also written several softwares that use DBF tables, with Dbase and a simple one with Lazarus I believe that the DBF tables are stable, my problem is not the table which opened with Dbase is with the correct records My worry is that when I click on the srollbar the content of the dbgrid is not stable, the good records disappear from the dbgrid which displays a repeating line the table is OK, I visualize the content with Dbase 1702 ... I must indeed be wrong, but where? I give you the code *. not of the two files This code it OK , but the problem are srollbar ??? I don't think it's lazarus ...... I have to do something bad, but where ?? Thank you for your help ---------------------------------------------------------------------- Fabius · 2021-06-02 07:37 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #unit importation; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, dbf, DB, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm7 }   TForm7 = class(TForm)    Button1: TButton;    Button2: TButton;  Edit1: TEdit;    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Memo1: TMemo;    Memo2: TMemo;    OpenDialog1: TOpenDialog;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  private   public   end; var  Form7: TForm7; implementationuses Unit3; {$R *.lfm} { TForm7 } procedure TForm7.Button1Click(Sender: TObject);Var i:integer;Var Nnnn:integer;begin  if OpenDialog1.Execute then    begin    Memo1.Lines.Clear;    Memo1.Lines.LoadFromFile(OpenDialog1.FileName);     /////////////supprimer les lignes du début    (* commentéSECURITY:NONE ENCODING:USASCIICHARSET:1252COMPRESSION:NONEOLDFILEUID:NONENEWFILEUID: NONE0INFO 20210526154523FRA967463549480INFOEUR181060003896746354948CHECKING 2020050100000020210525235959OTHER +12191.2520210526 +12191.2520210526*)      Memo1.Refresh;    Memo1.SetFocus;    Memo1.SelStart:=0;    Memo1.Refresh;      i:=0;      ///////////Memo1.Lines.Count-1      (*      Memo1.Lines[0];      for i := 0 to 80 do      begin      Memo1.Lines.Delete(i);      end;      *)    Memo1.SetFocus;    Memo1.SelStart:=0;    Edit1.Text := OpenDialog1.FileName;    Edit1.Visible:= True;     Label2.Caption:= 'Fichier en Cours : ' + IntToStr(Memo1.Lines.Count) + ' Lignes';    Label2.Visible:= True;     end;end; procedure TForm7.Button2Click(Sender: TObject);////////OFXVar i:integer;Var NombreT:integer;Var NomFichierEnCours : String;Var DateRow : String;Var DescriptionMouvement : String;Var Montant:String;Var MontantCredit : String;Var MontantDebit : String;Var MontantDebitNum : extended;Var MontantCreditNum : extended; Var fichier: TStringList;Var elements: String;Var buttonSelected : Integer;Var Ligness : Integer;Var LigneValueFid : String;Var LigneValueTravail : String;Var LigneValueMemo : String;Var LigneSTMTTRN : String;Var LigneSTMTTRN2 : String;Var LigneTRNTYPE  : String; begin   Form3.Dbf1.Active:= True;  Form3.Dbf1.First;    ///////////tester si la table de saisie à des enregistrements  if Form3.Dbf1.RecordCount > 0 Then  begin   messagedlg('La Table de destination n est pas vide .',mtinformation,[mbok],0); abort;  end;         //////////// enregistrement sur 9 lignes///20210525///20210525// /-0.23///6230510097758///VIREMENT UNITAIR N°2114500108875///./////////OTHER   ////////////////avertir  buttonSelected := MessageDlg('Lancer importation ? ',mtCustom,                              [mbYes,mbCancel], 0);   if buttonSelected = mrYes    then  begin   Ligness:=0;  NombreT := 0;   Form3.Dbf1.IndexName:= 'id';      Memo1.SetFocus;    Memo1.SelStart:=0;  for i := 0 to Memo1.Lines.Count-1 do    begin        if (Memo1.Lines.Strings[i] <> '') then      begin       ///////////// on démarre un enregistrement         if Pos ('', Memo1.Lines.Strings[i]) > 0 then  ////// 1 on débute un nouvel enregistrement avec la date           begin         Ligness := 0;           Montant := '';           DescriptionMouvement := '';           DateRow := '';           Memo2.Append('Debut');           MontantCreditNum := 0;           MontantDebitNum :=0;           MontantDebit :='';           MontantCredit := '';           end;                        ///OTHER           if Pos ('', Memo1.Lines.Strings[i]) > 0 then   //9           begin           Ligness := Ligness+1;           end;             //20210525           if Pos ('', Memo1.Lines.Strings[i]) > 0 then  ////// nouvel enregistrement avec la date  juste apres            begin           Ligness := Ligness+1;           DateRow := copy(Memo1.Lines.Strings[i], 11, 30);           Memo2.Append(DateRow);           end;            ///20210525           if Pos ('', Memo1.Lines.Strings[i]) > 0 then   ///2           begin           Ligness := Ligness+1;           LigneValueTravail := copy(Memo1.Lines.Strings[i], 10, 30);           Memo2.Append(LigneValueTravail);           end;            if Pos ('', Memo1.Lines.Strings[i]) > 0 then  //////le montant 3         begin           Montant := copy(Memo1.Lines.Strings[i], 9, 20);         Ligness := Ligness+1;                 if Pos ('+', Montant) > 0 then  //////le montant  est positif CREDIT                begin                MontantCredit := copy(Montant, 2, 20);                  Memo2.Append(MontantCredit);                  MontantCredit := MontantCredit.Replace('.', ',');                  MontantCreditNum :=  StrToFloat(MontantCredit);                end else                begin  ////le montant est un DEBIT                  MontantDebit := copy(Montant, 2, 20);                  Memo2.Append(MontantDebit);                MontantDebit := MontantDebit.Replace('.', ',');                MontantDebitNum := StrToFloat(MontantDebit);                end;             end;             ///6230510097758           if Pos ('', Memo1.Lines.Strings[i]) > 0 then    ////4           begin           Ligness := Ligness+1;            LigneValueFid := copy(Memo1.Lines.Strings[i], 8, 30);           Memo2.Append( LigneValueFid);           end;            if Pos ('', Memo1.Lines.Strings[i]) > 0 then  //////le descriptif   5           begin           Ligness := Ligness+1;           DescriptionMouvement := copy(Memo1.Lines.Strings[i], 7, 100);           Memo2.Append(DescriptionMouvement);           end;            ///.           if Pos ('', Memo1.Lines.Strings[i]) > 0 then  ///6           begin           Ligness := Ligness+1;           LigneValueMemo:= copy(Memo1.Lines.Strings[i], 0, 100);  ////////////la totalité           Memo2.Append(LigneValueMemo);         end;                     ///  noter le /  c la fin d un enregistrement           if  Pos('', Memo1.Lines.Strings[i]) > 0  then   ///7           begin                if (Ligness = 7) Then                 begin                   Memo2.Append('Fin');                  NombreT := NombreT + 1;                    Ligness:=0;                  Form3.Dbf1.Last;                   Form3.Dbf1.Append;                 Form3.Dbf1.FieldByName('compte').AsString := 'X';                 Form3.Dbf1.FieldByName('label').AsString := DescriptionMouvement;                    if MontantCreditNum > 0 then                   begin                        Form3.Dbf1.FieldByName('credit').asfloat := MontantCreditNum;                      Form3.Dbf1.FieldByName('debit').AsFloat :=0;                 end;                    if MontantDebitNum > 0 then                 begin                        Form3.Dbf1.FieldByName('debit').AsFloat := MontantDebitNum;                      Form3.Dbf1.FieldByName('credit').AsFloat :=0;                 end;                    Form3.Dbf1.Post;                   Form3.Dbf1.Refresh;                   end;                end;   /////////////FIn               end;  //////////// fin de test ligne blanche       Application.ProcessMessages;       end;         Form3.Dbf1.Refresh;         if (NombreT > 0) Then        begin        Label3.Caption:= 'Nombre ' + IntToStr(NombreT);          Label3.Visible:= True;        end;   end;   end;    end. ---------------------------------------------------------------------- Fabius · 2021-06-02 07:38 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit3; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, DB, dbf, memds, Forms, Controls, Graphics, Dialogs,  StdCtrls, ComCtrls, DBGrids, Grids, DBCtrls, Spin, ExtCtrls, Buttons,  RTTIGrids, SpinEx; type   { TForm3 }   TForm3 = class(TForm)    Bevel1: TBevel;  Bevel2: TBevel;    Bevel3: TBevel;    Button1: TButton;    Button2: TButton;    Button3: TButton;    Button4: TButton;    Button5: TButton;    Button6: TButton;    Button7: TButton;    Button8: TButton;    Button9: TButton;    ControlBar1: TControlBar;    DataSource1: TDataSource;    DataSource2: TDataSource;    DataSource3: TDataSource;    DataSource4: TDataSource;    DataSource5: TDataSource;    DataSource6: TDataSource;    DataSource7: TDataSource;    DBEdit1: TDBEdit;    DBEdit2: TDBEdit;    Dbf1: TDbf;    Dbf2: TDbf;    Dbf3: TDbf;    Dbf4: TDbf;    Dbf5: TDbf;    Dbf6: TDbf;    DBGrid2: TDBGrid;    DBGrid3: TDBGrid;    DBLookupComboBox1: TDBLookupComboBox;    DBLookupComboBox2: TDBLookupComboBox;    Edit1: TEdit;    Edit2: TEdit;    Edit3: TEdit;    CodeMouvement: TEdit;    Edit4: TEdit;    FloatSpinEditEx1: TFloatSpinEditEx;    FloatSpinEditEx2: TFloatSpinEditEx;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    Label5: TLabel;    Label6: TLabel;    Label7: TLabel;    MemDataset1: TMemDataset;    Tdebit: TEdit;    Tcredit: TEdit;    Tdbfcompte: TDbf;    DBGrid1: TDBGrid;    Label1: TLabel;    StatusBar1: TStatusBar;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure Button3Click(Sender: TObject);    procedure Button4Click(Sender: TObject);    procedure Button5Click(Sender: TObject);    procedure Button6Click(Sender: TObject);    procedure Button7Click(Sender: TObject);    procedure Button8Click(Sender: TObject);    procedure Button9Click(Sender: TObject);    procedure DataSource1DataChange(Sender: TObject; Field: TField);    procedure DBComboBox2Change(Sender: TObject);    procedure Dbf1BeforeOpen(DataSet: TDataSet);        procedure DBGrid1ColExit(Sender: TObject);    procedure DBGrid1DblClick(Sender: TObject);    procedure DBGrid2Enter(Sender: TObject);    procedure DBGrid3DblClick(Sender: TObject);    procedure DBLookupComboBox1Change(Sender: TObject);    procedure Edit2Change(Sender: TObject);    procedure Edit2Exit(Sender: TObject);    procedure FloatSpinEditEx1Exit(Sender: TObject);    procedure FloatSpinEditEx2Change(Sender: TObject);    procedure FloatSpinEditEx2Exit(Sender: TObject);    procedure FormActivate(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure FormShow(Sender: TObject);     procedure calcullignes;  private   public   end; var  Form3: TForm3; implementationuses Unit5 , Dbf_Common,dbf_dbffile,dbf_parser,d bf_prsdef,dbf_cursor,dbf_fields,dbf_pgfile,dbf_idxfile;{$R *.lfm} { TForm3 }    procedure TForm3.FormShow(Sender: TObject);begin  ////////    Form3.Top:= 100;    Form3.Left:= 100;          StatusBar1.SimpleText:= StatusBar1.Caption +' Calcul  ' ;       Dbf1.Refresh;  DBGrid1.Refresh;       calcullignes;end; procedure TForm3.DBGrid1ColExit(Sender: TObject);var Xcompte : string;var Xlabel : string; begin      if (DBGrid1.SelectedField.FieldName = 'DEBIT') OR (DBGrid1.SelectedField.FieldName = 'CREDIT') then      begin      StatusBar1.SimpleText:= StatusBar1.Caption +' Calcul  ' ;      calcullignes;      end;        if DBGrid1.SelectedField.FieldName = 'COMPTE' then    begin      StatusBar1.SimpleText:= 'Recherche : ';    if (DBGrid1.Columns[0].Field.IsNull) then      begin       end else begin      if (DBGrid1.Columns[0].Field.Value <> '') OR (DBGrid1.Columns[0].Field.Value <> 'Nil') then      begin      Xcompte := DBGrid1.Columns[0].Field.Value;      end else begin      Xcompte := '';      end;      end;                          //////////recherche dans la table compte , si le compte saisie existe       if (Xcompte <> '') then      begin       Tdbfcompte.IndexName := 'compte';    ////table des comptes sur index compte      if Tdbfcompte.Locate('compte', Xcompte, [loPartialKey, loCaseInsensitive]) then      begin          ////////////liste les champs de la table sur l enregistrement          Button1.Enabled:= True ;          StatusBar1.SimpleText:= StatusBar1.Caption +' Trouve Ok ' ;           Dbf1.Edit;          Dbf1.FieldByName('compte').AsString := Tdbfcompte.FieldByName('compte').AsString;          Dbf1.FieldByName('label').AsString := Tdbfcompte.FieldByName('label').AsString;          Dbf1.Post;         Xlabel := Tdbfcompte.FieldByName('label').AsString;         StatusBar1.SimpleText:= StatusBar1.Caption +' Ajouté ' + Xcompte + ' ' + Xlabel;        end else begin        Button1.Enabled:= False ;      StatusBar1.SimpleText := 'Non Trouvé : ' + Xcompte;        DBGrid1.SetFocus;        DBGrid1.SelectedColumn.FieldName := 'compte';        /////////Tdbfcompte. ['compte']. SetFocus;        end;    end;      end else begin      StatusBar1.SimpleText := 'Error Vide : ';     end;end; procedure TForm3.DBGrid1DblClick(Sender: TObject);begin  DBGrid1.Refresh;end; procedure TForm3.DBGrid2Enter(Sender: TObject);Var Rcherche:String;Var Rliasse:String;begin  ///// le dbgrill des compte recois le focus on affiche la liasse auquel est attaché le compte     if Tdbfcompte.FieldByName('compte').AsString <> '' then     begin        Rcherche := Tdbfcompte.FieldByName('compte').AsString;        Tdbfcompte.IndexName := 'compte';        if Tdbfcompte.SearchKeyPChar(PAnsiChar(AnsiString(Rcherche)), stGreaterEqual) then        begin         Rliasse := Tdbfcompte.FieldByName('liasse').AsString;         /////pointeur sur le liasse correspondante         Dbf6.IndexName := 'liasse';         if Dbf6.SearchKeyPChar(PAnsiChar(AnsiString(Rliasse)), stGreaterEqual) then         begin         Dbf6.Refresh;         end;         end;    end;end; procedure TForm3.DBGrid3DblClick(Sender: TObject);Var FFF : String;begin  ////////////double clic sur liasse , on affiche les comptes associés       if (DBEdit2.Text <> '') OR (DBEdit2.Text <> 'Nil') then      begin       //////////////appliquer filtre sur les comptes      FFF := DBEdit2.Text;      /////Tdbfcompte.IndexName:= 'liasse';      Tdbfcompte.Filter := 'liasse='+ QuotedStr(FFF);      Tdbfcompte.Filtered := true;      end; //   Tdbfcompteend; procedure TForm3.DBLookupComboBox1Change(Sender: TObject);begin  Edit4.Text:= DBLookupComboBox1.Text;  if Dbf1.RecordCount = 0 then  begin  Edit4.Color:=clblue;  end else begin   Edit4.Color:=clGreen;  end;end; procedure TForm3.Edit2Change(Sender: TObject);Var Rrrrr : String;begin  ////////////////champ de saissie  compte , il change on change la liste des comptes    Rrrrr := Edit2.Text;    Tdbfcompte.IndexName:= 'compte';    if Tdbfcompte.Locate('compte', Rrrrr, [loPartialKey, loCaseInsensitive]) then    begin    Tdbfcompte.Refresh;    Edit3.Text := Tdbfcompte.FieldByName('label').AsString;    end; end; procedure TForm3.Edit2Exit(Sender: TObject);begin   Edit3.SetFocus;end; procedure TForm3.FloatSpinEditEx1Exit(Sender: TObject);begin   Button8.SetFocus; end; procedure TForm3.FloatSpinEditEx2Change(Sender: TObject);begin end; procedure TForm3.FloatSpinEditEx2Exit(Sender: TObject);begin  FloatSpinEditEx1.SetFocus;end; procedure TForm3.FormActivate(Sender: TObject);begin  Dbf1.Refresh;  DBGrid1.Refresh;  DBGrid1.SetFocus;  DBGrid1.Update;  calcullignes;end; procedure TForm3.FormCreate(Sender: TObject);begin  ////// les chemins pour les tables   ///       CodeMouvement.Color:=;    Dbf1.First;  if Dbf1.RecordCount = 0 then  begin       Edit4.Color:=clblue;  end else begin     if Edit4.Text <> '' then     begin       Edit4.Color:=clGreen;       end else begin     Edit4.Color:=clblue;     end;  end;   end; procedure TForm3.Button1Click(Sender: TObject);Var NumeroMouvement : String;Var XXcompte : String ;begin  /////////////validation des écritures     /////////////verifier le DBComboBox1     if DBLookupComboBox2.Text = '' then    begin    messagedlg('Le journal est VIDE , impossible de confirmer les écritures dans les lignes.',mtinformation,[mbok],0);    abort;    end;     if Edit4.Text = '' then        ////////////// verifier la periode    begin    Edit4.Color:= clRed;    messagedlg('La periode est vide , selectionnez une periode dans la liste ou créez des periodes impossible de confirmer les écritures dans les lignes  .',mtinformation,[mbok],0);    abort;    end;       if DBLookupComboBox1.Text <> '' then    begin     /////////////on verifie que le code du mouvement existe ou pas    if CodeMouvement.Text = '' then    begin    /////////Determine le code mouvement    Dbf4.Active:= True;    Dbf4.IndexName:= 'Mouvement';    Dbf4.Last;    NumeroMouvement := Dbf4.FieldByName('Mouvement').AsString;    end else begin          ////////LE code Mouvement existe , on le copy    NumeroMouvement := CodeMouvement.Text;    end;         Tdbfcompte.IndexName := 'compte';      ////////boucle sur la table de saisie      dbf2.First;        while not dbf2.EOF do        begin      XXcompte := Dbf2.FieldByName('Mouvement').AsString;         if Tdbfcompte.SearchKeyPChar(PAnsiChar(AnsiString(XXcompte)), stGreaterEqual) then  //////////verification que le compte existe       begin         ///////// ajout dans les lignes apres que tout les comptes sont ok         end else begin              messagedlg('Lors de la verification le compte '+ XXcompte +' n est pas trouvé .',mtinformation,[mbok],0);              abort;         end;          end;           /////// ajout dans la table lignes        dbf2.First;      while not dbf2.EOF do        begin        Dbf4.Append;        Dbf4.FieldByName('compte').AsString := Dbf2.FieldByName('compte').AsString;        Dbf4.FieldByName('label').AsString := Dbf2.FieldByName('label').AsString;        Dbf4.FieldByName('debit').AsString := Dbf2.FieldByName('debit').AsString;        Dbf4.FieldByName('credit').AsString := Dbf2.FieldByName('credit').AsString;        Dbf4.FieldByName('Mouvement').AsString := NumeroMouvement;        Dbf4.FieldByName('journal').AsString := NumeroMouvement;        Dbf4.FieldByName('periode').AsString := Edit4.Text;        Dbf4.FieldByName('createur').AsString := 'x';        Dbf4.FieldByName('dossier').AsString := 'x';        Dbf4.Post;        end;         ////////affiche la form des lignes    if Form5.Visible = false then Form5.Visible := true else Form5.BringToFront ;     end else begin    messagedlg('Le journal est VIDE , impossible de continuer .',mtinformation,[mbok],0);    end; end; procedure TForm3.Button2Click(Sender: TObject);var Xcompte : string;begin    //////////////////cherche un compte    Xcompte := Edit1.Text;    Tdbfcompte.IndexName:= 'compte';    if Tdbfcompte.Locate('compte', Xcompte, [loPartialKey, loCaseInsensitive]) then    begin    DBGrid2.SetFocus;    end;  end; procedure TForm3.Button3Click(Sender: TObject);begin  /////////////ajouter dans ligne de saisie le compte en cours  remplacement     if DBEdit1.text <>'' then    begin       DBEdit1.Color := clGreen;       DBGrid1.Columns[0].Field.Value := Tdbfcompte.FieldByName('compte').AsString;        if DBGrid1.Columns[1].Field.Value = '' Then        begin        DBGrid1.Columns[1].Field.Value := Tdbfcompte.FieldByName('label').AsString;        end;      end else begin          DBEdit1.Color := clRed ;          messagedlg('Compte NON Trouvé Ou Vide .',mtinformation,[mbok],0);          StatusBar1.SimpleText:= 'Ce compte n existe pas ';    end;      end; procedure TForm3.Button4Click(Sender: TObject);begin  //////////////////ajouter en fin de table        if DBEdit1.text <>'' then    begin    DBEdit1.Color := clGreen;    Dbf1.Append;    ////Dbf1.Edit;    Dbf1.FieldByName('compte').AsString := Tdbfcompte.FieldByName('compte').AsString;    Dbf1.FieldByName('label').AsString := Tdbfcompte.FieldByName('label').AsString;    Dbf1.Post;    end else begin          DBEdit1.Color := clRed ;          messagedlg('Compte NON Trouvé Ou Vide .',mtinformation,[mbok],0);          StatusBar1.SimpleText:= 'Ce compte n existe pas ';    end; end; procedure TForm3.Button5Click(Sender: TObject);begin  ////////////mettre le compte dans le champ de saisie individuel     try     Edit2.Text := Tdbfcompte.FieldByName('compte').AsString;     Edit3.Text := Tdbfcompte.FieldByName('label').AsString;     Edit3.SetFocus;     finally     end;  end; procedure TForm3.Button6Click(Sender: TObject);begin  /////////////////enlever les filtres des comptes    /////Tdbfcompte.cancelrange;    Tdbfcompte.Filtered := False;    Tdbfcompte.IndexName:= 'compte';    Tdbfcompte.First;    Tdbfcompte.Refresh; end; procedure TForm3.Button7Click(Sender: TObject);Var buttonSelected : Integer;begin  ///////////lignes de saisie à Zero  buttonSelected := MessageDlg('Supprimer les lignes de saisies ? ',mtCustom,                            [mbYes,mbCancel], 0);  if buttonSelected = mrYes    then  begin   Dbf1.Exclusive:= True;   Dbf1.Zap;   Dbf1.Exclusive:= False;   Dbf1.Refresh;   DBGrid1.Refresh;   calcullignes;   Tcredit.Text:='0';   Tdebit.Text:= '0';   Label2.Caption:= '';   Label2.Visible:= False;   Label7.Visible:= False;   ////messagedlg('Resultat Supprime ok  .',mtinformation,[mbok],0);  end;   ////////// end; procedure TForm3.Button8Click(Sender: TObject);begin  ////////////ajouter une ligne    Edit2.SetFocus; calcullignes;end; procedure TForm3.Button9Click(Sender: TObject);begintry  dbf1.Delete;  calcullignes;finallyend;end; procedure TForm3.DataSource1DataChange(Sender: TObject; Field: TField);begin  //////////Dbf1.Refresh;end; procedure TForm3.DBComboBox2Change(Sender: TObject);begin end; procedure TForm3.Dbf1BeforeOpen(DataSet: TDataSet);begin end; procedure TForm3.calcullignes;Var TotalDebit : Extended;Var TotalCredit : Extended;Var SoldeDebit : Extended;Var SoldeCredit : Extended;Var NnnnLignes : Integer;begin          ////////////calculer les montant debit et creditNnnnLignes :=0;        Dbf2.DisableControls;        Dbf2.First;         TotalDebit := 0;      TotalCredit :=0;         while not dbf2.EOF do        begin       NnnnLignes := NnnnLignes+1;          TotalDebit := TotalDebit + Dbf2.FieldByName('debit').AsFloat;          TotalCredit := TotalCredit + Dbf2.FieldByName('credit').AsFloat;          dbf2.Next;        end;           Dbf2.EnableControls;         Tcredit.Text:= FloatToStr(TotalCredit);        Tdebit.Text:= FloatToStr(TotalDebit);          if (TotalCredit = TotalDebit) AND ( (TotalDebit > 0) AND (TotalCredit > 0) )  then         begin         Tcredit.Color:=clLime;         Tdebit.Color:=clLime;         Label2.Caption := 'Validation Ok';         end else begin         Tcredit.Color:=clRed;         Tdebit.Color:=clRed;         Label2.Caption := 'Validation ImPossible';          if TotalCredit > TotalDebit then         begin         SoldeDebit := TotalCredit - TotalDebit;          Label2.Caption := 'Solde Au Debit: ' + FloatToStr(SoldeDebit);         end else begin         SoldeCredit := TotalDebit - TotalCredit;          Label2.Caption := 'Solde Au Credit: ' + FloatToStr(SoldeCredit);         end;             end;          Dbf2.Refresh;         Dbf1.Refresh;         DBGrid1.Refresh;         if (NnnnLignes>0) then         begin         Label7.Visible:= True;       Label7.Caption:= 'Nombre de Ligne : ' + IntToStr(NnnnLignes);        end; end;     end. ---------------------------------------------------------------------- jamie · 2021-06-02 10:04 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   unit Unit3; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, DB, dbf, memds, Forms, Controls, Graphics, Dialogs,  StdCtrls, ComCtrls, DBGrids, Grids, DBCtrls, Spin, ExtCtrls, Buttons,  RTTIGrids, SpinEx; type   { TForm3 }   TForm3 = class(TForm)    Bevel1: TBevel;  Bevel2: TBevel;    Bevel3: TBevel;    Button1: TButton;    Button2: TButton;    Button3: TButton;    Button4: TButton;    Button5: TButton;    Button6: TButton;    Button7: TButton;    Button8: TButton;    Button9: TButton;    ControlBar1: TControlBar;    DataSource1: TDataSource;    DataSource2: TDataSource;    DataSource3: TDataSource;    DataSource4: TDataSource;    DataSource5: TDataSource;    DataSource6: TDataSource;    DataSource7: TDataSource;    DBEdit1: TDBEdit;    DBEdit2: TDBEdit;    Dbf1: TDbf;    Dbf2: TDbf;    Dbf3: TDbf;    Dbf4: TDbf;    Dbf5: TDbf;    Dbf6: TDbf;    DBGrid2: TDBGrid;    DBGrid3: TDBGrid;    DBLookupComboBox1: TDBLookupComboBox;    DBLookupComboBox2: TDBLookupComboBox;    Edit1: TEdit;    Edit2: TEdit;    Edit3: TEdit;    CodeMouvement: TEdit;    Edit4: TEdit;    FloatSpinEditEx1: TFloatSpinEditEx;    FloatSpinEditEx2: TFloatSpinEditEx;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    Label5: TLabel;    Label6: TLabel;    Label7: TLabel;    MemDataset1: TMemDataset;    Tdebit: TEdit;    Tcredit: TEdit;    Tdbfcompte: TDbf;    DBGrid1: TDBGrid;    Label1: TLabel;    StatusBar1: TStatusBar;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure Button3Click(Sender: TObject);    procedure Button4Click(Sender: TObject);    procedure Button5Click(Sender: TObject);    procedure Button6Click(Sender: TObject);    procedure Button7Click(Sender: TObject);    procedure Button8Click(Sender: TObject);    procedure Button9Click(Sender: TObject);    procedure DataSource1DataChange(Sender: TObject; Field: TField);    procedure DBComboBox2Change(Sender: TObject);    procedure Dbf1BeforeOpen(DataSet: TDataSet);        procedure DBGrid1ColExit(Sender: TObject);    procedure DBGrid1DblClick(Sender: TObject);    procedure DBGrid2Enter(Sender: TObject);    procedure DBGrid3DblClick(Sender: TObject);    procedure DBLookupComboBox1Change(Sender: TObject);    procedure Edit2Change(Sender: TObject);    procedure Edit2Exit(Sender: TObject);    procedure FloatSpinEditEx1Exit(Sender: TObject);    procedure FloatSpinEditEx2Change(Sender: TObject);    procedure FloatSpinEditEx2Exit(Sender: TObject);    procedure FormActivate(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure FormShow(Sender: TObject);     procedure calcullignes;  private   public   end; var  Form3: TForm3; implementationuses Unit5 , Dbf_Common,dbf_dbffile,dbf_parser,d bf_prsdef,dbf_cursor,dbf_fields,dbf_pgfile,dbf_idxfile;{$R *.lfm} { TForm3 }    procedure TForm3.FormShow(Sender: TObject);begin  ////////    Form3.Top:= 100;    Form3.Left:= 100;          StatusBar1.SimpleText:= StatusBar1.Caption +' Calcul  ' ;       Dbf1.Refresh;  DBGrid1.Refresh;       calcullignes;end; procedure TForm3.DBGrid1ColExit(Sender: TObject);var Xcompte : string;var Xlabel : string; begin      if (DBGrid1.SelectedField.FieldName = 'DEBIT') OR (DBGrid1.SelectedField.FieldName = 'CREDIT') then      begin      StatusBar1.SimpleText:= StatusBar1.Caption +' Calcul  ' ;      calcullignes;      end;        if DBGrid1.SelectedField.FieldName = 'COMPTE' then    begin      StatusBar1.SimpleText:= 'Recherche : ';    if (DBGrid1.Columns[0].Field.IsNull) then      begin       end else begin      if (DBGrid1.Columns[0].Field.Value <> '') OR (DBGrid1.Columns[0].Field.Value <> 'Nil') then      begin      Xcompte := DBGrid1.Columns[0].Field.Value;      end else begin      Xcompte := '';      end;      end;                          //////////recherche dans la table compte , si le compte saisie existe       if (Xcompte <> '') then      begin       Tdbfcompte.IndexName := 'compte';    ////table des comptes sur index compte      if Tdbfcompte.Locate('compte', Xcompte, [loPartialKey, loCaseInsensitive]) then      begin          ////////////liste les champs de la table sur l enregistrement          Button1.Enabled:= True ;          StatusBar1.SimpleText:= StatusBar1.Caption +' Trouve Ok ' ;           Dbf1.Edit;          Dbf1.FieldByName('compte').AsString := Tdbfcompte.FieldByName('compte').AsString;          Dbf1.FieldByName('label').AsString := Tdbfcompte.FieldByName('label').AsString;          Dbf1.Post;         Xlabel := Tdbfcompte.FieldByName('label').AsString;         StatusBar1.SimpleText:= StatusBar1.Caption +' Ajouté ' + Xcompte + ' ' + Xlabel;        end else begin        Button1.Enabled:= False ;      StatusBar1.SimpleText := 'Non Trouvé : ' + Xcompte;        DBGrid1.SetFocus;        DBGrid1.SelectedColumn.FieldName := 'compte';        /////////Tdbfcompte. ['compte']. SetFocus;        end;    end;      end else begin      StatusBar1.SimpleText := 'Error Vide : ';     end;end; procedure TForm3.DBGrid1DblClick(Sender: TObject);begin  DBGrid1.Refresh;end; procedure TForm3.DBGrid2Enter(Sender: TObject);Var Rcherche:String;Var Rliasse:String;begin  ///// le dbgrill des compte recois le focus on affiche la liasse auquel est attaché le compte     if Tdbfcompte.FieldByName('compte').AsString <> '' then     begin        Rcherche := Tdbfcompte.FieldByName('compte').AsString;        Tdbfcompte.IndexName := 'compte';        if Tdbfcompte.SearchKeyPChar(PAnsiChar(AnsiString(Rcherche)), stGreaterEqual) then        begin         Rliasse := Tdbfcompte.FieldByName('liasse').AsString;         /////pointeur sur le liasse correspondante         Dbf6.IndexName := 'liasse';         if Dbf6.SearchKeyPChar(PAnsiChar(AnsiString(Rliasse)), stGreaterEqual) then         begin         Dbf6.Refresh;         end;         end;    end;end; procedure TForm3.DBGrid3DblClick(Sender: TObject);Var FFF : String;begin  ////////////double clic sur liasse , on affiche les comptes associés       if (DBEdit2.Text <> '') OR (DBEdit2.Text <> 'Nil') then      begin       //////////////appliquer filtre sur les comptes      FFF := DBEdit2.Text;      /////Tdbfcompte.IndexName:= 'liasse';      Tdbfcompte.Filter := 'liasse='+ QuotedStr(FFF);      Tdbfcompte.Filtered := true;      end; //   Tdbfcompteend; procedure TForm3.DBLookupComboBox1Change(Sender: TObject);begin  Edit4.Text:= DBLookupComboBox1.Text;  if Dbf1.RecordCount = 0 then  begin  Edit4.Color:=clblue;  end else begin   Edit4.Color:=clGreen;  end;end; procedure TForm3.Edit2Change(Sender: TObject);Var Rrrrr : String;begin  ////////////////champ de saissie  compte , il change on change la liste des comptes    Rrrrr := Edit2.Text;    Tdbfcompte.IndexName:= 'compte';    if Tdbfcompte.Locate('compte', Rrrrr, [loPartialKey, loCaseInsensitive]) then    begin    Tdbfcompte.Refresh;    Edit3.Text := Tdbfcompte.FieldByName('label').AsString;    end; end; procedure TForm3.Edit2Exit(Sender: TObject);begin   Edit3.SetFocus;end; procedure TForm3.FloatSpinEditEx1Exit(Sender: TObject);begin   Button8.SetFocus; end; procedure TForm3.FloatSpinEditEx2Change(Sender: TObject);begin end; procedure TForm3.FloatSpinEditEx2Exit(Sender: TObject);begin  FloatSpinEditEx1.SetFocus;end; procedure TForm3.FormActivate(Sender: TObject);begin  Dbf1.Refresh;  DBGrid1.Refresh;  DBGrid1.SetFocus;  DBGrid1.Update;  calcullignes;end; procedure TForm3.FormCreate(Sender: TObject);begin  ////// les chemins pour les tables   ///       CodeMouvement.Color:=;    Dbf1.First;  if Dbf1.RecordCount = 0 then  begin       Edit4.Color:=clblue;  end else begin     if Edit4.Text <> '' then     begin       Edit4.Color:=clGreen;       end else begin     Edit4.Color:=clblue;     end;  end;   end; procedure TForm3.Button1Click(Sender: TObject);Var NumeroMouvement : String;Var XXcompte : String ;begin  /////////////validation des écritures     /////////////verifier le DBComboBox1     if DBLookupComboBox2.Text = '' then    begin    messagedlg('Le journal est VIDE , impossible de confirmer les écritures dans les lignes.',mtinformation,[mbok],0);    abort;    end;     if Edit4.Text = '' then        ////////////// verifier la periode    begin    Edit4.Color:= clRed;    messagedlg('La periode est vide , selectionnez une periode dans la liste ou créez des periodes impossible de confirmer les écritures dans les lignes  .',mtinformation,[mbok],0);    abort;    end;       if DBLookupComboBox1.Text <> '' then    begin     /////////////on verifie que le code du mouvement existe ou pas    if CodeMouvement.Text = '' then    begin    /////////Determine le code mouvement    Dbf4.Active:= True;    Dbf4.IndexName:= 'Mouvement';    Dbf4.Last;    NumeroMouvement := Dbf4.FieldByName('Mouvement').AsString;    end else begin          ////////LE code Mouvement existe , on le copy    NumeroMouvement := CodeMouvement.Text;    end;         Tdbfcompte.IndexName := 'compte';      ////////boucle sur la table de saisie      dbf2.First;        while not dbf2.EOF do        begin      XXcompte := Dbf2.FieldByName('Mouvement').AsString;         if Tdbfcompte.SearchKeyPChar(PAnsiChar(AnsiString(XXcompte)), stGreaterEqual) then  //////////verification que le compte existe       begin         ///////// ajout dans les lignes apres que tout les comptes sont ok         end else begin              messagedlg('Lors de la verification le compte '+ XXcompte +' n est pas trouvé .',mtinformation,[mbok],0);              abort;         end;          end;           /////// ajout dans la table lignes        dbf2.First;      while not dbf2.EOF do        begin        Dbf4.Append;        Dbf4.FieldByName('compte').AsString := Dbf2.FieldByName('compte').AsString;        Dbf4.FieldByName('label').AsString := Dbf2.FieldByName('label').AsString;        Dbf4.FieldByName('debit').AsString := Dbf2.FieldByName('debit').AsString;        Dbf4.FieldByName('credit').AsString := Dbf2.FieldByName('credit').AsString;        Dbf4.FieldByName('Mouvement').AsString := NumeroMouvement;        Dbf4.FieldByName('journal').AsString := NumeroMouvement;        Dbf4.FieldByName('periode').AsString := Edit4.Text;        Dbf4.FieldByName('createur').AsString := 'x';        Dbf4.FieldByName('dossier').AsString := 'x';        Dbf4.Post;        end;         ////////affiche la form des lignes    if Form5.Visible = false then Form5.Visible := true else Form5.BringToFront ;     end else begin    messagedlg('Le journal est VIDE , impossible de continuer .',mtinformation,[mbok],0);    end; end; procedure TForm3.Button2Click(Sender: TObject);var Xcompte : string;begin    //////////////////cherche un compte    Xcompte := Edit1.Text;    Tdbfcompte.IndexName:= 'compte';    if Tdbfcompte.Locate('compte', Xcompte, [loPartialKey, loCaseInsensitive]) then    begin    DBGrid2.SetFocus;    end;  end; procedure TForm3.Button3Click(Sender: TObject);begin  /////////////ajouter dans ligne de saisie le compte en cours  remplacement     if DBEdit1.text <>'' then    begin       DBEdit1.Color := clGreen;       DBGrid1.Columns[0].Field.Value := Tdbfcompte.FieldByName('compte').AsString;        if DBGrid1.Columns[1].Field.Value = '' Then        begin        DBGrid1.Columns[1].Field.Value := Tdbfcompte.FieldByName('label').AsString;        end;      end else begin          DBEdit1.Color := clRed ;          messagedlg('Compte NON Trouvé Ou Vide .',mtinformation,[mbok],0);          StatusBar1.SimpleText:= 'Ce compte n existe pas ';    end;      end; procedure TForm3.Button4Click(Sender: TObject);begin  //////////////////ajouter en fin de table        if DBEdit1.text <>'' then    begin    DBEdit1.Color := clGreen;    Dbf1.Append;    ////Dbf1.Edit;    Dbf1.FieldByName('compte').AsString := Tdbfcompte.FieldByName('compte').AsString;    Dbf1.FieldByName('label').AsString := Tdbfcompte.FieldByName('label').AsString;    Dbf1.Post;    end else begin          DBEdit1.Color := clRed ;          messagedlg('Compte NON Trouvé Ou Vide .',mtinformation,[mbok],0);          StatusBar1.SimpleText:= 'Ce compte n existe pas ';    end; end; procedure TForm3.Button5Click(Sender: TObject);begin  ////////////mettre le compte dans le champ de saisie individuel     try     Edit2.Text := Tdbfcompte.FieldByName('compte').AsString;     Edit3.Text := Tdbfcompte.FieldByName('label').AsString;     Edit3.SetFocus;     finally     end;  end; procedure TForm3.Button6Click(Sender: TObject);begin  /////////////////enlever les filtres des comptes    /////Tdbfcompte.cancelrange;    Tdbfcompte.Filtered := False;    Tdbfcompte.IndexName:= 'compte';    Tdbfcompte.First;    Tdbfcompte.Refresh; end; procedure TForm3.Button7Click(Sender: TObject);Var buttonSelected : Integer;begin  ///////////lignes de saisie à Zero  buttonSelected := MessageDlg('Supprimer les lignes de saisies ? ',mtCustom,                            [mbYes,mbCancel], 0);  if buttonSelected = mrYes    then  begin   Dbf1.Exclusive:= True;   Dbf1.Zap;   Dbf1.Exclusive:= False;   Dbf1.Refresh;   DBGrid1.Refresh;   calcullignes;   Tcredit.Text:='0';   Tdebit.Text:= '0';   Label2.Caption:= '';   Label2.Visible:= False;   Label7.Visible:= False;   ////messagedlg('Resultat Supprime ok  .',mtinformation,[mbok],0);  end;   ////////// end; procedure TForm3.Button8Click(Sender: TObject);begin  ////////////ajouter une ligne    Edit2.SetFocus; calcullignes;end; procedure TForm3.Button9Click(Sender: TObject);begintry  dbf1.Delete;  calcullignes;finallyend;end; procedure TForm3.DataSource1DataChange(Sender: TObject; Field: TField);begin  //////////Dbf1.Refresh;end; procedure TForm3.DBComboBox2Change(Sender: TObject);begin end; procedure TForm3.Dbf1BeforeOpen(DataSet: TDataSet);begin end; procedure TForm3.calcullignes;Var TotalDebit : Extended;Var TotalCredit : Extended;Var SoldeDebit : Extended;Var SoldeCredit : Extended;Var NnnnLignes : Integer;begin          ////////////calculer les montant debit et creditNnnnLignes :=0;        Dbf2.DisableControls;        Dbf2.First;         TotalDebit := 0;      TotalCredit :=0;         while not dbf2.EOF do        begin       NnnnLignes := NnnnLignes+1;          TotalDebit := TotalDebit + Dbf2.FieldByName('debit').AsFloat;          TotalCredit := TotalCredit + Dbf2.FieldByName('credit').AsFloat;          dbf2.Next;        end;           Dbf2.EnableControls;         Tcredit.Text:= FloatToStr(TotalCredit);        Tdebit.Text:= FloatToStr(TotalDebit);          if (TotalCredit = TotalDebit) AND ( (TotalDebit > 0) AND (TotalCredit > 0) )  then         begin         Tcredit.Color:=clLime;         Tdebit.Color:=clLime;         Label2.Caption := 'Validation Ok';         end else begin         Tcredit.Color:=clRed;         Tdebit.Color:=clRed;         Label2.Caption := 'Validation ImPossible';          if TotalCredit > TotalDebit then         begin         SoldeDebit := TotalCredit - TotalDebit;          Label2.Caption := 'Solde Au Debit: ' + FloatToStr(SoldeDebit);         end else begin         SoldeCredit := TotalDebit - TotalCredit;          Label2.Caption := 'Solde Au Credit: ' + FloatToStr(SoldeCredit);         end;             end;          Dbf2.Refresh;         Dbf1.Refresh;         DBGrid1.Refresh;         if (NnnnLignes>0) then         begin         Label7.Visible:= True;       Label7.Caption:= 'Nombre de Ligne : ' + IntToStr(NnnnLignes);        end; end;     end.        Please use the "#" above in the menus so you can paste your code between and it will show like you see here, now. Please package your program within a ZIP file and attached it here. Use the menus provided in Lazarus. PROJECT:   PUBLISH PROJECT it maybe different in your language. ---------------------------------------------------------------------- Zvoni · 2021-06-02 10:21 I don't look at source-code where units, variables, controls etc. haven't been properly named.... I'm not going to guess, what Button1 stands for...... ---------------------------------------------------------------------- jamie · 2021-06-02 10:42 I can understand much of what's there. 45 years of coding helps with that grey matter functionality up there. I am sure if you were looking at the code with samples it would come to you quickly.. ---------------------------------------------------------------------- Zvoni · 2021-06-02 12:38 Jamie, yeah, i know. Call me a lazy bugger ---------------------------------------------------------------------- Fabius · 2021-06-05 09:20 I found, the problem comes from not putting an index in the dbgrid