Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-03

Package

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antonio Fortuny

Hi Folks.

I've built my first Lazarus package. When it is dynamically created in a test program, it works as it is supposed to work.
When I drop it onto a form and test it with code, looks OK. So far, so good.
But when it try to remove the component from the form where it is has been dropped, the IDE crashes with an Access violation exception I wonder if I didn't forget something in the either construcor or the destructor or both.
At runtime the program crashes with a segmentation fault

constructor TCustomControlTimer.Create(AOwner: TComponent);
begin
   inherited Create(AOwner);
   FTH := TTimerThread.Create;
   FTH.FreeOnTerminate := False;
end;
destructor TCustomControlTimer.Destroy;
var
   Elapsed: Cardinal;
begin
   if Assigned(FTH) then begin
     if FTH.Active then begin
       FTH.Terminate;
       // d?bloquer la boucle d'attente
       FTH.EnableEvent.SetEvent;
     end;
     Elapsed := 0;
     while FTH.Active do begin
       Sleep(50);
       if Elapsed > 5000 then
         Break;
       Inc(Elapsed, 50)
     end;
     FreeAndNil(FTH);
   end;
end;

Antonio.

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com

Reply by email

Mattias Gaertner
to Antonio Fortuny
Show quoted text 38 lines
Hi Folks. I've built my first Lazarus package. When it is dynamically created in a test program, it works as it is supposed to work. When I drop it onto a form and test it with code, looks OK. So far, so good. But when it try to remove the component from the form where it is has been dropped, the IDE crashes with an Access violation exception I wonder if I didn't forget something in the either construcor or the destructor or both. At runtime the program crashes with a segmentation fault constructor TCustomControlTimer.Create(AOwner: TComponent); begin inherited Create(AOwner); FTH := TTimerThread.Create; FTH.FreeOnTerminate := False; end; destructor TCustomControlTimer.Destroy; var Elapsed: Cardinal; begin if Assigned(FTH) then begin if FTH.Active then begin FTH.Terminate; // d?bloquer la boucle d'attente FTH.EnableEvent.SetEvent; end; Elapsed := 0; while FTH.Active do begin Sleep(50); if Elapsed > 5000 then Break; Inc(Elapsed, 50) end; FreeAndNil(FTH); end;
inherited;
end;

Mattias

Reply by email

Antonio Fortuny
to Mattias Gaertner

Le 10/03/2014 18:20, Mattias Gaertner a ?crit :

Show quoted text 7 lines
if Elapsed > 5000 then Break; Inc(Elapsed, 50) end; FreeAndNil(FTH); end; inherited;

This solves part of the problem. Thanks Mattias. :-) It was to obvious that I guess I was on another planet whent thinking on the problem.
Now I still have the problem in the IDE:
- dropping the non visual component on a form is OK
- running the program with that component dynamically created is OK
- when deleting the component from the form, in the IDE, Lazarus crashes with an access violation exception

Antonio.

Show quoted text 9 lines
> end; Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com

Reply by email

Mattias Gaertner
to Antonio Fortuny
Show quoted text 17 lines
Le 10/03/2014 18:20, Mattias Gaertner a ?crit : > if Elapsed > 5000 then > Break; > Inc(Elapsed, 50) > end; > FreeAndNil(FTH); > end; > inherited; This solves part of the problem. Thanks Mattias. :-) It was to obvious that I guess I was on another planet whent thinking on the problem. Now I still have the problem in the IDE: - dropping the non visual component on a form is OK - running the program with that component dynamically created is OK - when deleting the component from the form, in the IDE, Lazarus crashes with an access violation exception

BTW, why does your component start a thread at design time?

Mattias

Reply by email

Antonio Fortuny
to Mattias Gaertner

Le 11/03/2014 13:12, Mattias Gaertner a ?crit :

Show quoted text 20 lines
On Tue, 11 Mar 2014 08:37:14 +0100 Antonio Fortuny wrote: > Le 10/03/2014 18:20, Mattias Gaertner a ?crit : >> if Elapsed > 5000 then >> Break; >> Inc(Elapsed, 50) >> end; >> FreeAndNil(FTH); >> end; >> inherited; > This solves part of the problem. Thanks Mattias. :-) > It was to obvious that I guess I was on another planet whent thinking on > the problem. > Now I still have the problem in the IDE: > - dropping the non visual component on a form is OK > - running the program with that component dynamically created is OK > - when deleting the component from the form, in the IDE, Lazarus crashes > with an access violation exception BTW, why does your component start a thread at design time?

Yep ! Mattias you are my muse :-D
After a careful reading of the code it appears that the internal thread created had this line in the constructor.

   FreeOnTerminate := True;

Aaaaaaargh ! :-[
So simple, so obvious, so easy and I missed it.
Is was on another planet, defintely.
Not it all runs nicely.

Thanks,

Antonio.

Show quoted text 8 lines
Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140311/954fc819/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: jjhffgdb.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140311/954fc819/attachment.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: ghcjjhgd.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140311/954fc819/attachment-0001.jpg>

Reply by email

Antonio Fortuny
to Antonio Fortuny

Le 11/03/2014 13:37, Antonio Fortuny a ?crit :

Show quoted text 7 lines
Yep ! Mattias you are my muse :-D After a careful reading of the code it appears that the internal thread created had this line in the constructor. ? FreeOnTerminate := True; Aaaaaaargh ! :-[ So simple, so obvious, so easy and I missed it. Is was on another planet, defintely.

I was on ...

Not it all runs nicely.

Now it all ...

Sorry for the garbage.

Show quoted text 40 lines
Thanks, Antonio. > Mattias > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert?? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner ------------------------------------------------------------------------ <http://www.avast.com/> Ce courrier ??lectronique ne contient aucun virus ou logiciel malveillant parce que la protection Antivirus avast! <http://www.avast.com/> est active. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140311/ca78f570/attachment-0001.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 2306 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140311/ca78f570/attachment-0002.jpe> -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 921 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140311/ca78f570/attachment-0003.jpe>

Reply by email