Recent

Author Topic: OnClick SIGSEVG Exception  (Read 3333 times)

pmesquita

  • Jr. Member
  • **
  • Posts: 62
OnClick SIGSEVG Exception
« on: June 24, 2021, 03:12:54 pm »
Personal..
I have a problem here that I don't know anymore what it could be...

I have a Form (fsMDIForm) where when I click on the TSpeedButton button, all the OnClick event routines are executed (basically it is an SQL that authenticates the user in the database) but when debugging, when executing the entire Begin/End block, an exception SIGSEVG is generated ..

Through CallStack I saw that the error is on line 2911 of control.inc

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TControl.Click;
  3.  
  4.   function OnClickIsActionExecute: boolean;
  5.   begin
  6.     Result:=false;
  7.     if Action=nil then exit;
  8.     if not Assigned(Action.OnExecute) then exit;
  9.     if not Assigned(FOnClick) then exit;
  10.     Result:=CompareMethods(TMethod(FOnClick),TMethod(Action.OnExecute));
  11.   end;
  12.  
  13. var
  14.   CallAction: Boolean;
  15. begin
  16.   //DebugLn(['TControl.Click ',DbgSName(Self)]);
  17.   CallAction:=(not (csDesigning in ComponentState)) and (ActionLink <> nil);
  18.  
  19.   // first call our own OnClick if it differs from Action.OnExecute
  20.   if Assigned(FOnClick)
  21.   and ((not CallAction) or (not OnClickIsActionExecute)) then
  22. [b]    FOnClick(Self);[/b]
  23.   // then trigger the Action
  24.   if CallAction then
  25.     ActionLink.Execute(Self);
  26. end;
  27.  

Windows 10 x64
Lazarus 2.0.12
FPC 3.2.0
Build Mode: Debug


Any idea what it might be or any tips from how can i debug...?

ADMGNS

  • New Member
  • *
  • Posts: 30
  • keep it simple and smart
Re: OnClick SIGSEVG Exception
« Reply #1 on: June 26, 2021, 10:39:55 pm »
hello

as my experience, compare with nil have potantial problems.. instead of, kindly you must use 'assigned' always to check..

regs

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: OnClick SIGSEVG Exception
« Reply #2 on: June 26, 2021, 11:02:44 pm »
Assigned just checks for nil...

MarkMLl

  • Hero Member
  • *****
  • Posts: 6688
Re: OnClick SIGSEVG Exception
« Reply #3 on: June 26, 2021, 11:19:18 pm »
Assigned just checks for nil...

Except where it's checking whether a function returning a pointer (etc.) is assigned, in which case it /specifically/ looks at the function rather than evaluating it and looking at the result.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jamie

  • Hero Member
  • *****
  • Posts: 6134
Re: OnClick SIGSEVG Exception
« Reply #4 on: June 27, 2021, 01:31:50 am »
I don't know, I see trouble ahead using Assigned to validate pointers from a function, that is directly wrapping it around a function.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: OnClick SIGSEVG Exception
« Reply #5 on: June 27, 2021, 07:06:50 am »
I don't know, I see trouble ahead using Assigned to validate pointers from a function, that is directly wrapping it around a function.

I think what Mark means is validating a var of a procedural type pointing to a function returning a pointer, such as:
Code: Pascal  [Select][+][-]
  1. type
  2.   APtrFunction = function: Pointer;
  3.  
  4. var
  5.   TheFunction: APtrFunction;
  6.  
  7. {...}
  8.  
  9.   if Assigned(TheFunction) then
  10.     { ... };

In that specific case Assigned() is guaranteed to check if the var TheFunction is Nil, rather than whether the result of a call to it returns Nil.

I don't remember where I read that, though; sorry.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6688
Re: OnClick SIGSEVG Exception
« Reply #6 on: June 27, 2021, 09:13:59 am »
I don't know, I see trouble ahead using Assigned to validate pointers from a function, that is directly wrapping it around a function.

I think what Mark means is validating a var of a procedural type pointing to a function returning a pointer, such as:
Code: Pascal  [Select][+][-]
  1. type
  2.   APtrFunction = function: Pointer;
  3.  
  4. var
  5.   TheFunction: APtrFunction;
  6.  
  7. {...}
  8.  
  9.   if Assigned(TheFunction) then
  10.     { ... };

In that specific case Assigned() is guaranteed to check if the var TheFunction is Nil, rather than whether the result of a call to it returns Nil.

I don't remember where I read that, though; sorry.

Yes, that's what I mean. It's a consequence of Pascal (unlike Modula-2 and C) not distinguishing between a (pointer to) a function and the result of the function's invocation by whether the function name is followed by parentheses.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018