Recent

Author Topic: [SOLVED] Can't get rid of a SIGSEGV error using CSVDocument  (Read 4443 times)

burtgummer

  • Newbie
  • Posts: 3
[SOLVED] Can't get rid of a SIGSEGV error using CSVDocument
« on: November 12, 2014, 04:35:59 pm »
Hello everyone,

First of all I want to apologize for my poor skills in database handling, many years ago I had a basic formation on Lazarus and free pascal and recently I wanted to make a program for the ice cream company of my dad to make his life easier, all was going quite well until I started getting SIGSEGV errors linked apparently to the CSVDocument unit that I have imported from this link:

http://wiki.freepascal.org/CsvDocument

I also used this the mainfrm.pas as model to create my program

http://sourceforge.net/p/lazarus-ccr/svn/3062/tree/components/csvdocument/demo/mainfrm.pas

In the beginning my program was working fine (main menu window was working, I could open a second form on which I was able to select the database with a TOpenDialog, the database path was already stored in a registery so the user could just press continue or load a specific file, then when continue was pressed the inventory window was showing up in which I already had configured a barcode scanner reading procedure (but this part is not responsible of the bug as it only consist of a setfocus code and some visible:=true/false on label elements, no interaction with the database yet)

Then the problem appeared when the CSVDocument started being used, the strange thing is that it appeared the first time when in the third form I clicked on a button that was programmed as follows:

procedure TForm2.Button3Click(Sender: TObject);
begin
   UpdateView;
end;         

I had a SIGSEGV error, then when pressed ok, the CSVDocument page popped up in the source editor and the line "the Result := FRows.Count;" was evidenced in grey, this line comes from the function below:

function TCSVDocument.GetRowCount: Integer;
begin
  Result := FRows.Count;
end;

I had multiple times this SIGSEGV error showing up and each time linked apparently to the CSVDocument while using the Form, and while I was trying to fix the problem it started crashing right after the launch of UNIT1 with the same error, since then I can't get the unit to show up in a stable way. When pressing the execute button (green triangle in lazarus) It starts compiling everything, then the main menu of my program pops up and instantly the application crashes showing me that nice error message you can see in attachment.

Of course I've been looking for an answer over the internet but never found a topic that concerned specifically the CSVDocument and a related SIGSEGV error.

The strange thing is that the error now shows up as soon as I start the program and this is very odd as the program is supposed to load Unit1 first that is a very simple unit that only have the function to execute showmodal codes for other forms when clicking on buttons.

So please If anyone would be kind enough to help me here I would be thankful
You will find two pictures of the program at the moment when the error shows up and the CSVdocument shows the faulty line, and I also attached the debug log that will be, I hope, more useful.

Sincerely, thanks for your help
Thierry
« Last Edit: November 18, 2014, 07:58:49 am by burtgummer »

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Can't get rid of a SIGSEGV error using CSVDocument
« Reply #1 on: November 12, 2014, 07:19:01 pm »
Ensure that you are not trying to focus on a control or a form while a modal form is open
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Can't get rid of a SIGSEGV error using CSVDocument
« Reply #2 on: November 12, 2014, 07:46:57 pm »
You may need to post the full code (or a cut-down version that demonstrates the problem) to get more specific help.

burtgummer

  • Newbie
  • Posts: 3
Re: Can't get rid of a SIGSEGV error using CSVDocument
« Reply #3 on: November 14, 2014, 08:54:46 am »
Hello and sorry for my late reply, yesterday I had lot of work and haven't found any time to test anything.

So today I managed to get rid of the error but my problem isn't solved yet as I will need the parameter I removed, the mainfrm.pas program that I found uses a TIdleTimer in many procedures that is named UpdateTimer. In this TIdleTimer there is a field OnTimer and in the demo of the CSVDocument I saw that this field was filled with the name of the procedure UpdateTimerTimer, so when I had written this procedure in my program I added UpdateTimerTimer in the field OnTimer.
This seems to have generated many errors.
To eliminate the causes one by one I just set the related procedures as comments // and finally got an error related to the TIdleTimer field no longer linked to a procedure and a box asked me if I wanted to "break" the settings of this TIdleTimer, so I said yes and the field OnTimer just returned blank. So now the program runs well again but I don't understand how this happened.

I'll wait a little more before closing this subject as I will reactivate all procedures and do more testing to try to find the source of the error but if any of you have an idea of why the OnTimer field made the program crash on start all of a sudden that would be helpful.

In attachment you will find the programs of the involved Forms when the procedures were still active.
« Last Edit: November 14, 2014, 08:57:25 am by burtgummer »

burtgummer

  • Newbie
  • Posts: 3
Re: Can't get rid of a SIGSEGV error using CSVDocument
« Reply #4 on: November 17, 2014, 03:58:19 pm »
Hello,
I finally managed to solve my problem, for those who will read the topic in the future here was the exact problem and the solution (probably not the best and it may look very stupid for the pros here, but it worked for me in this particular case and I'm quite happy to see my StringGrid filling itself as it's supposed to when asked to):

Previously I had this declaration which was responsible of the problem:

Code: [Select]
procedure TForm2.FormCreate(Sender: TObject);
begin
   FDoc := TCSVDocument.create;
   FDoc.delimiter := ',';
   FDoc.LoadFromFile(OpenDialog2.FileName);
end;

The problem is it seemed that the value of the OpenDialog2 was loaded in FDoc before the actual load of the file.csv into OpenDialog2, so then when I tried to manipulate data in the FDoc I had sigsegv errors linked to the CSVDocument.

To avoid this problem I created a TEdit that I called "initializer" on the form where my stringgrid, opendialog, savedialog, updatetimer are (Form2).

Since the opendialog2 was activated from Form5, I did the confirmation button programming as follows:

Code: [Select]
procedure TForm5.Button1Click(Sender: TObject);
begin
  inventaire.Form2.OpenDialog2.Filename:=label2.caption;    //(label2.caption contains the path of the file loaded at the last execution)
  Inventaire.Form2.initializer.text:='initialization';        //(the TEdit located in form2 is triggered by this change)
  Inventaire.Form2.initializer.clear;                              //(since I don't need the data in it I clear it's content)
  Inventaire.Form2.Showmodal;                                  //(opens my inventaire Form)
  Form5.close;                                                             //(closes the csv file selection/load menu)
end;

This TEdit will have it's content changed when the actual load of the csv file is done, now let's see what the program does in Form2 just after having loaded the csv file:

Code: [Select]
procedure TForm2.initializerChange(Sender: TObject);  (This is the TEdit named Initializer)
begin
   FDoc := TCSVDocument.create;
   FDoc.delimiter := ',';
   FDoc.LoadFromFile(OpenDialog2.FileName);
end;
As this last procedure is executed in Form2 and not from Form5 I no longer have a SIGSEGV error, as I said in the beginning of my message, my approach may seem silly, but it's the first thing I came with that solved my problem and I only have a small experience in Lazarus programming.

Well, I hope that this could help someone in the future, the subject can be closed and marked as solved.
Thank you all for your help
« Last Edit: November 18, 2014, 07:58:18 am by burtgummer »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Can't get rid of a SIGSEGV error using CSVDocument
« Reply #5 on: November 17, 2014, 04:01:28 pm »
Please don't close subjects. There may be useful posts afterwards.

To mark a thread solved: edit the first post, edit the subject and put [SOLVED] in front.

Note: to get your code to display correctly in forum posts, please surround them with [ code ] [ /code ] tags (without the spaces).

Also, in general, often it helps to just post the entire project (sources only, via project/publish project, then zip the result) you are having problems with as the problem may not be in the location you think it is. That way, it is also easier for others to compile and check out the problem.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018