Recent

Author Topic: [SOLVED] DBGrid Index  (Read 1336 times)

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[SOLVED] DBGrid Index
« on: March 20, 2019, 11:23:25 pm »
I have a query with multiple tables.
In this query I can have ID's that can have the same number but with a different. Letter attached to it.
So it can be 12 R or 12 L, with other things attached to it.
I used this code to locate the ID (which is in this example 12)
Code: Pascal  [Select][+][-]
  1. TQ_Evaluaties.Locate('ID', Save_ID, []);
But when I have to number 12's it goes wrong.

Is it possible to get the DBGrid Index number so that I can select the correct index when I for example have edited the data in a different form?


This is the actual code I use.
Code: Pascal  [Select][+][-]
  1. procedure TForm_Evaluatie_Overzicht.BT_EditClick(Sender: TObject);
  2. var Save_ID, Save_WD: Integer;
  3.     Save_RL: string;
  4.     fel2005: TForm_Evaluatie_2005_Linesman;
  5.     fel2018: TForm_Evaluatie_2018_Linesman;
  6.     fel2019: TForm_Evaluatie_2019_Linesman;
  7.     fer2005: TForm_Evaluatie_2005_Referee;
  8.     fer2018: TForm_Evaluatie_2018_Referee;
  9.     fer2019: TForm_Evaluatie_2019_Referee;
  10. begin
  11.   if TQ_Evaluaties.RecordCount = 0 then begin
  12.     Form_Message.MsgWindow(mUitroep, bOK,
  13.       'There is no Evaluation to Edit !! ' + sCrLf +
  14.       'First add a Evaluation !!', PrgNaam);
  15.     Exit;
  16.   end;
  17.   Save_ID := TQ_Evaluaties.FieldByName('ID').AsInteger;
  18.   Save_WD := TQ_Evaluaties.FieldByName('Wed_ID').AsInteger;
  19.   Save_RL := TQ_Evaluaties.FieldByName('TBL').AsString;
  20.   case Save_RL of
  21.     'R': begin
  22.            case Save_ID of  // Save_ID = 4 -=> Test rapport
  23.              2, 3,
  24.              5..10  : fer2005 := TForm_Evaluatie_2005_Referee.Create(Self);
  25.              11..14 : fer2018 := TForm_Evaluatie_2018_Referee.Create(Self);
  26.            else
  27.              fer2019 := TForm_Evaluatie_2019_Referee.Create(Self);
  28.            end; // case
  29.            try
  30.              case Save_ID of  // Save_ID = 4 -=> Test rapport
  31.                2, 3,
  32.                5..10  : fer2005.ShowEvaluatieReferee (Save_ID, Save_WD);
  33.                11..14 : fer2018.ShowEvaluatieReferee (Save_ID, Save_WD);
  34.              else
  35.                fer2019.ShowEvaluatieReferee (Save_ID, Save_WD);
  36.              end; // case
  37.            finally
  38.              case Save_ID of
  39.                2, 3, 5..10 : fer2005.Free;
  40.                11..14 : fer2018.Free;
  41.              else
  42.                fer2019.Free;
  43.              end; // case
  44.            end;  // try
  45.          end;  // Referee
  46.     'L': begin
  47.            case Save_ID of  // Save_ID = 14 -=> Test rapport
  48.              2..13,
  49.              15..23 : fel2005 := TForm_Evaluatie_2005_Linesman.Create(Self);
  50.              24     : fel2018 := TForm_Evaluatie_2018_Linesman.Create(Self);
  51.            else
  52.              begin  // alle andere zijn nieuwe rapporten gemaakt in 2018-2019 en erna.
  53.                fel2019 := TForm_Evaluatie_2019_Linesman.Create(Self);
  54.              end
  55.           end; // case
  56.           try
  57.             case Save_ID of  // Save_ID = 14 -=> Test rapport
  58.               2..13,
  59.               15..23 : fel2005.ShowEvaluatieLinesman (Save_ID, Save_WD);
  60.               24     : fel2018.ShowEvaluatieLinesman (Save_ID, Save_WD);
  61.             else
  62.               begin  // alle andere zijn nieuwe rapporten gemaakt in 2018-2019 en erna.
  63.                 fel2019.ShowEvaluatieLinesman (Save_ID, Save_WD);
  64.               end
  65.             end; // case
  66.            finally
  67.              case Save_ID of
  68.                2..13, 15..23 : fel2005.Free;
  69.                24 : fel2018.Free;
  70.              else
  71.                fel2019.Free;
  72.              end; // case
  73.            end;  // try
  74.          end;  // Linesman
  75.   end;     // case
  76.   TQ_Evaluaties.Refresh;
  77.   TQ_Evaluaties.Locate('ID', Save_ID, []);
  78. end;     // BT_EditClick
« Last Edit: March 20, 2019, 11:36:38 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: DBGrid Index
« Reply #1 on: March 20, 2019, 11:35:57 pm »
Next Time I have to google first before asking a question here.
Found my own solution AGAIN  :D


Code: Pascal  [Select][+][-]
  1. TQ_Evaluaties.Locate('ID;TBL', VarArrayOf([Save_ID, Save_RL]), []);


It's explained here http://wiki.freepascal.org/locate
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