Bookstore

Recent

Author Topic: [Solved] Access Violation from the ribbon but not from the form  (Read 706 times)

madref

  • Hero Member
  • *****
  • Posts: 772
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] Access Violation from the ribbon but not from the form
« on: February 24, 2020, 03:30:43 am »
I have build this ribbon and that works as it should be.
When I have the screen open as shown in the attachment AND when I press [Edit Game] in the ribbon I get an acmes violation.
But when I press the [Edit]-button on the form it works.


Why do I get an access violation?


This is the code from the ribbon
Code: Pascal  [Select]
  1. procedure TForm_Ribbon.Ribbon_Wedstrijden_OverzichtClick(Sender: TObject);
  2. begin
  3.   case TBCButton(Sender).Tag of
  4.     1: ShowMessage ('Nieuw');
  5.     2: Form_Wedstrijd_Overzicht.Wedstrijden_Bewerken;
  6.     3: ShowMessage ('Delete');
  7.     4: ShowMessage ('Mail');
  8.   end;  // case
  9. end;     // Ribbon_Wedstrijden_OverzichtClick
  10.  

This is the code in the form.
Code: Pascal  [Select]
  1. procedure TForm_Wedstrijd_Overzicht.BT_GameEditClick(Sender: TObject);
  2. begin
  3.   Wedstrijden_Bewerken;
  4. end;
  5.  
  6.  
  7. procedure TForm_Wedstrijd_Overzicht.Wedstrijden_Bewerken;
  8. var
  9.   wID, i: Integer;
  10. //     Grid_Wedstrijden: TStringGrid; defined in the form
  11.  
  12. begin
  13.   ShowMessage ('xxxxxxxxxx'); // this works
  14.   wID := StrToInt (Grid_wedstrijden.Cells[0, Grid_wedstrijden.Row]);  // this gives the error when accessed from the ribbon
  15.   showmessage (IntToStr(wid))
  16. end;     // BT_GameEditClick
  17.  
« Last Edit: March 03, 2020, 04:29:01 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 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

howardpc

  • Hero Member
  • *****
  • Posts: 3358
Re: Access Violation from the ribbon but not from the form
« Reply #1 on: February 24, 2020, 06:24:16 am »
Perhaps the issue is related to focus and whether the accessed grid is the active control or not?
But, as ever, without compilable code to reproduce and debug the issue, others can only make guesses.

madref

  • Hero Member
  • *****
  • Posts: 772
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Access Violation from the ribbon but not from the form
« Reply #2 on: February 24, 2020, 10:17:41 am »
I have made a working example.
Please open the Test.r4db file in program.


I had to make 3 archives.
Put all files in the same directory

You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 772
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Access Violation from the ribbon but not from the form
« Reply #3 on: February 24, 2020, 10:18:51 am »
archive 2

You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 772
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Access Violation from the ribbon but not from the form
« Reply #4 on: February 24, 2020, 10:19:09 am »
archive 3
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

howardpc

  • Hero Member
  • *****
  • Posts: 3358
Re: Access Violation from the ribbon but not from the form
« Reply #5 on: February 25, 2020, 02:24:00 pm »
I don't know what the issue is.
I tried installing the libraries you use, and removing the Mac-specific stuff to get your app to compile on Linux. It compiles, but fails to run when I try to load the data file with the error shown, so your form displaying data in a grid never shows for me.

Perhaps it is a Mac-specific issue anyway, which I cannot help you with.

My suggestion would be not to have the ribbon form as your main form, but to incorporate a ribbon into the grid form, and keep that as the main form. That at least would avoid issues to do with accessing a grid on a form that is not the active form (if that is the source of the problem, which of course it may not be).

madref

  • Hero Member
  • *****
  • Posts: 772
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Access Violation from the ribbon but not from the form
« Reply #6 on: February 25, 2020, 05:35:58 pm »
The open file does work....so you should be able to open the correct database


When I open the given database it work.


i uploaded the database again maybe there was some kind of error.


And if that does not work. this is the definition go tbl_versie
Code: Pascal  [Select]
  1.     cSQL := '';
  2.     cSQL := 'CREATE TABLE tbl_Versie (' +
  3.             'Versie_ID WORD PRIMARY KEY ASC, ' +
  4.             'Versie_Update WORD' +
  5.             ')';
  6.     Connect_RefereeDB.ExecuteDirect(cSQL);
  7.     cSQL := '';
  8.     cSQL := cSQL + 'INSERT INTO tbl_Versie ';
  9.     cSQL := cSQL + 'VALUES (4, 1)';
  10.     Connect_RefereeDB.ExecuteDirect(cSQL);
  11.  
« Last Edit: February 25, 2020, 05:45:08 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 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 772
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Access Violation from the ribbon but not from the form
« Reply #7 on: March 03, 2020, 11:44:35 am »
Does any one know a solution to my problem?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 772
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Access Violation from the ribbon but not from the form
« Reply #8 on: March 03, 2020, 04:28:29 pm »
I have been experimenting with different options.
And when the form is being made while the program is running I get the ' access violation'.
But when I make the form during startup I don't get the acces violation.


In other words the form has to be created in the .LPR-file.
So this file looks now like:
Code: Pascal  [Select]
  1. program referee4_DB;
  2.  
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6.  
  7. uses
  8.   {$IFDEF UNIX}
  9.   cthreads,
  10.   {$ENDIF}
  11.   Interfaces, // this includes the LCL widgetset
  12.   ....., referee_ribbon, referee_logoscherm, referee_wedstrijd_overzicht;
  13.  
  14.  
  15. {$R *.res}
  16.  
  17.  
  18. begin
  19.   Application.Title:='Referee4_DB';
  20.   RequireDerivedFormResource:=True;
  21.   Application.Scaled:=True;
  22.   Application.Initialize;
  23.   Application.CreateForm(TForm_Ribbon, Form_Ribbon);
  24.   Application.CreateForm(TForm_Logo, Form_Logo);
  25.   .....
  26.   .....
  27.   Application.CreateForm(TForm_Wedstrijd_Overzicht, Form_Wedstrijd_Overzicht);
  28.   Application.Run;
  29. end.
  30.  
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave