External: SIGSEGV lazarus / 12-Debugger ---------------------------------------------------------------------- Herman_SA · 2010-01-14 17:12 I wrote a relative long program and didn't have any problems. However when I added very simple code to read data from a .dat file I received the following error. Project example_p.exe raised exception class 'External SIGSEV'. When I ran the debugger I noticed that I didn't always get the message on the same line of code. But its alway when I want to use this particaular function, the rest of program uses a lot of .dat files and read them with no problem. Here is the code that crash: procedure TForm1.MenuEditStockClick(Sender: TObject); var     StockFile               : File of Stock;     StockRekord             : Stock;     sCost                   : String;     sMark                   : String;     sPrice                  : String; begin   PnlNewBooks.Visible       := False;   pnlState.Visible          := False;   PnlStock.Visible          := True;   MemStock.Lines.Clear;   MemStock.WantTabs         := True;   NewDir                    := CurrentDir + 'Databases\Stock.dat';   MemStock.Lines.Add        ('Code' + #9 + 'Qty' + #9 + 'Item' + #9 + 'Description' + #9 + 'Brand' + #9 +  'Unit' + #9 +  'Cost' + #9 +  'Markup' + #9 +  'Price');   AssignFile              (StockFile, NewDir);     If FileExists (NewDir) then       begin       Reset (StockFile);        While not EOF(StockFile) do         begin           Read                (StockFile, StockRekord);           With StockRekord do           MemStock.Lines.Add    (Code + #9 + IntToStr(Qty) + #9 + ProdServ + #9 + Description + #9 + Brand + #9 + sUnit + #9 + FloatToStrF(CostPrice, ffFixed, 10, 2) + #9 + FloatToStrF(Markup, ffFixed, 10, 2) + #9);         end;         CloseFile(StockFile);       end     else       ShowMessage('Database not found'); end; Specs: Win 7 home Premium 32bit Intel Celeron 1.8Ghz Lazarus version 0.9.28.2 beta. Please help. ---------------------------------------------------------------------- Herman_SA · 2010-01-14 17:20 Sorry forgot to mention that sometimes I get the desired results and a can see the data from the file. But if I repeat it a few times, it crash. Other times I have the problem right from the first try. ---------------------------------------------------------------------- zakwas · 2010-01-14 21:15 Quote from: Herman_SA on January 14, 2010, 06:12:06 pmWhen I ran the debugger I noticed that I didn't always get the message on the same line of code. But its alway when I want to use this particaular function, the rest of program uses a lot of .dat files and read them with no problem. On which line of your code do you get errors, and what are this errors? ---------------------------------------------------------------------- Herman_SA · 2010-01-15 07:09 Usaully its somewhere between these lines: AssignFile              (StockFile, NewDir);     If FileExists (NewDir) then       begin       Reset (StockFile);        While not EOF(StockFile) do         begin           Read                (StockFile, StockRekord);           With StockRekord do           MemStock.Lines.Add    (Code + #9 + IntToStr(Qty) + #9 + ProdServ + #9 + Description + #9 + Brand + #9 + sUnit + #9 + FloatToStrF(CostPrice, ffFixed, 10, 2) + #9 + FloatToStrF(Markup, ffFixed, 10, 2) + #9);         end;         CloseFile(StockFile);       end     else       ShowMessage('Database not found'); end; And it is the "'External SIGSEV'." error I mentioned above. I did receive that error on the line wit the memo output (memstock.lines.....), once on the Closefile, and even after it completed the code without any problems (i would follow it step for step through the whole piece of code and then it crash right after it). That is why I don't know if it is wrong code, but then again it only happens in this part of the program. I'm stunned. ---------------------------------------------------------------------- Herman_SA · 2010-01-15 08:25 ok so today for the first time I got the problem exactly on the same line 3 times in a row. all of them when the "Read                (StockFile, StockRekord);" runs through the second time. First time works fine but because of while it returns to do the read function again...this is when it crashes ---------------------------------------------------------------------- zakwas · 2010-01-15 14:21 The problem is weird. What is the structure of StockRecord ? BTW, I think is better replace this part Code: [Select]...   AssignFile              (StockFile, NewDir);   If FileExists (NewDir) then       begin       Reset (StockFile);        While not EOF(StockFile) do ... with: Code: [Select]...   If FileExists (NewDir) then       begin         AssignFile(StockFile, NewDir);         Reset (StockFile);         While not EOF(StockFile) do .... ---------------------------------------------------------------------- Herman_SA · 2010-01-16 08:14 Stock     = Record             Code                : String[20];             ProdServ            : String[20];             sUnit               : String[20];             CostPrice           : Real;                        SellPrice           : Real;                        Markup              : Real;             Supplier            : String;             Qty                 : Integer;             Brand               : String[20];             Description         : String[20];         end; ---------------------------------------------------------------------- theo · 2010-01-16 09:16 "Supplier" length depends on the complier setting for LongStrings. if {$H-} it has a length of 256, if {$H+} it only stores the Pointer to the AnsiString. Replace with ShortString to avoid problems. ---------------------------------------------------------------------- zakwas · 2010-01-16 18:48 Quote from: theo on January 16, 2010, 10:16:04 am"Supplier" length depends on the complier setting for LongStrings. if {$H-} it has a length of 256, if {$H+} it only stores the Pointer to the AnsiString. Replace with ShortString to avoid problems. I thought that the strings type is 255 bytes long. And the first byte defines how long is whole string, but always compiler reserves 255 bytes. However maybe, just change Code: [Select]Supplier : String; to Code: [Select]Supplier : String[255]; ---------------------------------------------------------------------- theo · 2010-01-16 19:08 Quote from: zakwas on January 16, 2010, 07:48:42 pmI thought that the strings type is 255 bytes long. No, it depends on the compiler switch: http://wiki.freepascal.org/String Usually AnsiString is enabled {$H+}, in this case you cannot save the string in a record, because it has no fixed size. ---------------------------------------------------------------------- zakwas · 2010-01-16 19:29 Quote from: theo on January 16, 2010, 08:08:37 pmQuote from: zakwas on January 16, 2010, 07:48:42 pmI thought that the strings type is 255 bytes long. No, it depends on the compiler switch: http://wiki.freepascal.org/String Usually AnsiString is enabled {$H+}, in this case you cannot save the string in a record, because it has no fixed size. OK , my experience is based on Turbo Pascal/Delphi. ---------------------------------------------------------------------- theo · 2010-01-16 20:41 Quote from: zakwas on January 16, 2010, 08:29:38 pmOK , my experience is based on Turbo Pascal/Delphi. Long- or AnsiString was also the default type in Delphi since v2 http://delphi.about.com/od/beginners/l/aa071800a.htm ---------------------------------------------------------------------- Herman_SA · 2010-01-20 09:30 Hi. I made it a shortstring Supplier            : String; I made Supplier            : String[100]; and that solved it. I can't believe it's such a stupid little thing. Thank you so much. You really helped me alot.