Recent

Author Topic: [Solved] Can't find error in unit/form  (Read 1890 times)

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] Can't find error in unit/form
« on: November 07, 2017, 07:24:00 pm »
I have the following unit/form.
It shows and edits a license.
Code: Pascal  [Select][+][-]
  1. unit referee_licentiesinfo;
  2.  
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6.  
  7. interface
  8.  
  9.  
  10. uses
  11.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  12.   DbCtrls, sqldb, db;
  13.  
  14.  
  15. type
  16.  
  17.  
  18.   { TForm_Licentie_Info }
  19.  
  20.  
  21.   TForm_Licentie_Info = class(TForm)
  22.     BT_LicentieCancel: TButton;
  23.     BT_LicentieOk: TButton;
  24.     BT_LicentieUpdate: TButton;
  25.     DB_LicentieID: TDBEdit;
  26.     DB_Licentie: TDBEdit;
  27.     DB_LicentieUitleg: TDBEdit;
  28.     DS_Licenties: TDataSource;
  29.     GroupBox_Supervisor: TGroupBox;
  30.     GroupBox_SupervisorActie: TGroupBox;
  31.     lbl_Licentie: TLabel;
  32.     lbl_Discription: TLabel;
  33.     TQ_Licenties: TSQLQuery;
  34.     procedure BT_LicentieCancelClick(Sender: TObject);
  35.     procedure BT_LicentieOkClick(Sender: TObject);
  36.     procedure BT_LicentieUpdateClick(Sender: TObject);
  37.     procedure DS_LicentiesStateChange(Sender: TObject);
  38.   private
  39.     { private declarations }
  40.     procedure UpdateLicentie;
  41.   public
  42.     { public declarations }
  43.     procedure ShowLicentie(ID: integer);
  44.   end;
  45.  
  46.  
  47. var
  48.   Form_Licentie_Info: TForm_Licentie_Info;
  49.  
  50.  
  51. implementation
  52.  
  53.  
  54. uses referee_funkties, referee_informatie, referee_meldingen, referee_types;
  55.  
  56.  
  57. {$R *.lfm}
  58.  
  59.  
  60. { TForm_Licentie_Info }
  61.  
  62.  
  63. procedure TForm_Licentie_Info.BT_LicentieCancelClick(Sender: TObject);
  64. begin
  65.   Close;
  66. end;     // BT_LicentieCancelClick
  67.  
  68.  
  69. procedure TForm_Licentie_Info.BT_LicentieOkClick(Sender: TObject);
  70. begin
  71.   if (DB_Licentie.Text='') or (DB_LicentieUitleg.Text = '') then begin
  72.     Form_Message.MsgWindow(mStop, bOK, 'The field License and/or Discription is/are empty !!' + chr(13)+chr(10)+chr(13)+chr(10)+
  73.          'Please make sure that' + chr(13)+chr(10)+ 'this are filled !!', PrgNaam);
  74.     Exit;
  75.   end;
  76.   UpdateLicentie;
  77.   Close;
  78. end;     // BT_LicentieOkClick
  79.  
  80.  
  81. procedure TForm_Licentie_Info.BT_LicentieUpdateClick(Sender: TObject);
  82. begin
  83.   if (DB_Licentie.Text='') or (DB_LicentieUitleg.Text = '') then begin
  84.     Form_Message.MsgWindow(mStop, bOK, 'The field License and/or Discription is/are empty !!' + chr(13)+chr(10)+chr(13)+chr(10)+
  85.          'Please make sure that' + chr(13)+chr(10)+ 'this are filled !!', PrgNaam);
  86.     Exit;
  87.   end;
  88.   UpdateLicentie;
  89. end;     // BT_LicentieUpdateClick
  90.  
  91.  
  92. procedure TForm_Licentie_Info.DS_LicentiesStateChange(Sender: TObject);
  93. begin
  94.   // we veranderen de status van de knoppen om alleen opslaan mogelijk
  95.   // te maken bij insert of edit status
  96.   BT_LicentieUpdate.Enabled := DS_Licenties.State in [dsEdit, dsInsert];
  97.   BT_LicentieCancel.Enabled := True; // cancel mag altijd
  98.   // Toch altijd de OK-knop. Meer intiutief
  99.   BT_LicentieOk.Enabled := true;
  100.   BT_LicentieOk.Caption := 'Close';
  101.   if DS_Licenties.State in [dsEdit, dsInsert] then
  102.     BT_LicentieOk.Caption := 'OK + Close';
  103. end;     // DS_LicentiesStateChange
  104.  
  105.  
  106. procedure TForm_Licentie_Info.ShowLicentie(ID: integer);
  107. var cSQL: string;
  108.     MaxID: integer;
  109. begin
  110.   TQ_Licenties.Active := false; // maar ze zouden al gesloten moeten zijn
  111. //  cSQL := 'SELECT * FROM tbl_Licenties_Keuze WHERE Licentie_ID = :Licentie_ID;';
  112.   cSQL := 'SELECT * FROM tbl_Licenties_Keuze WHERE Licentie_ID = ' + IntToStr(ID) + ';';
  113.   TQ_Licenties.DataBase := Form_Information.Connect_RefereeDB;
  114.   TQ_Licenties.SQL.Text := cSQL;
  115. //  TQ_Licenties.ParamByName('Licentie_ID').AsInteger := ID; // dit is mooier
  116.   //TQ_Licenties.Active:=True;
  117.  
  118.  
  119.   If ID <> 0 then
  120.     begin
  121.       TQ_Licenties.Open;
  122.       TQ_Licenties.Edit; // niet doen want hij staat reeds op AutoEdit, wel zo mooi
  123.       // toch even edit gedaan omdat die autoedit niet lekker werkt ????
  124.     end
  125.   else begin
  126.     TQ_Licenties.Open;
  127.     TQ_Licenties.Insert; // wel altijd direct een insert
  128.     MaxID := StrToIntDef(MLookup('MAX(Licentie_ID)','tbl_Licenties_Keuze','1=1'), 0);
  129.     MaxID := MaxID + 1;
  130.     TQ_Licenties.FieldByName('Licentie_ID').AsInteger := MaxID;
  131.     TQ_Licenties.FieldByName('Licentie').AsString := '';
  132.     TQ_Licenties.FieldByName('Licentie_Uitleg').AsString := '';
  133.   end;  // if
  134.   ShowModal;
  135. end;     // ShowLicentie
  136.  
  137.  
  138. //------------------------------------------------------------------------------
  139. // Sla de gegevens van de supervisore divisie op.
  140. //------------------------------------------------------------------------------
  141. procedure TForm_Licentie_Info.UpdateLicentie;
  142. begin
  143.   //Sla het op in de tabel
  144.   if TQ_Licenties.State in [dsEdit, dsInsert] then begin
  145.     TQ_Licenties.Post;
  146.     TQ_Licenties.ApplyUpdates;  // <==-- ERROR !!!
  147.     if Form_Information.Trans_RefereeDB.Active then
  148.       Form_Information.Trans_RefereeDB.CommitRetaining;
  149.   end;  // if
  150. end;     // UpdateLicentie
  151.  
  152.  
  153. end.
Every time i push the update or ok button i try to update my record but instead i get an error (line 146).
The error is described in the attachment.


What am i doing wrong (again)?
« Last Edit: November 22, 2017, 11:01:13 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Can't find error in unit/form
« Reply #1 on: November 22, 2017, 11:01:01 pm »
I finally solved it.


I had the UpdateMode set to upWhereKeyOnly and it had to be set to upWhereChanged
« Last Edit: November 22, 2017, 11:11:45 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

 

TinyPortal © 2005-2018