Sign in Join

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

Mailing lists / lazarus / 2011-12

Trying to troubleshoot error

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Chris Kelling

I'm trying to read from a file and populate a stringgrid, and keep getting 'Project spares.exe raised an exception class 'External error: SIGSEGV' when trying to convert an integer to string. Running the application gets the dialog: Access Violation Press OK to ignore and risk data corruption or cancel to kill the program. Clicking OK brings the grid up with the header row populated, and the first field in the first non-fixed row (Cells[0,1]) with the proper value, but the rest of the table is blank. I put a try...finally block in and now the IDE breaks at the read statement. Any suggestions? The code snippet follows.

procedure TfrmDashBoard.GetInvExecute(Sender: TObject;
                                        DB : string);
var
   {stockItem type is a record with the following structure:
     recordID    : longint;
     ClassNumber : integer;
     PartNumber  : string;
     Make        : String;
     TypeofEqip  : string;
     Model       : string;
     Description : string;
     quantity    : integer;
     location    : string;
     price       : real;    }
    workspace : Stockitem;
    row       : longint;
begin
      assignfile(inventory,db);
      try
      reset(inventory);
      row := 0;
      while not eof(inventory) do
            begin
                read(inventory,workspace);
                inc(row);
                if db = 'Ops' then
                  with stgInvOps do
                       begin
                            Cells[0,row] :=
inttostr(workspace.ClassNumber);
                            Cells[1,row] := workspace.PartNumber;
                            Cells[2,row] := workspace.Make;
                            Cells[3,row] := workspace.TypeofEqip;
                            Cells[4,row] := workspace.Model;
                            Cells[5,row] := workspace.Description;
                            Cells[6,row] :=
inttostr(workspace.quantity);
                            Cells[7,row] := workspace.location;
                            Cells[8,row] := floattostr(workspace.price);
                       end
                else

thanks.
windows7 32bit, SP1
Lazarus 0.90.30
FPC: 2.4.2
-Chris

Reply by email

Sven Barth
to Chris Kelling
Chris Kelling wrote 9 lines
I'm trying to read from a file and populate a stringgrid, and keep getting 'Project spares.exe raised an exception class 'External error: SIGSEGV' when trying to convert an integer to string. Running the application gets the dialog: Access Violation Press OK to ignore and risk data corruption or cancel to kill the program. Clicking OK brings the grid up with the header row populated, and the first field in the first non-fixed row (Cells[0,1]) with the proper value, but the rest of the table is blank. I put a try...finally block in and now the IDE breaks at the read statement. Any suggestions? The code snippet follows.

First guess:
You need to set the number of rows and columns in the grid. It does not auto expand.

Regards,
Sven

Reply by email

Bart
to Chris Kelling: I'm trying to read from a file and populate a stringgrid, and keep getting 'Project…
Chris Kelling wrote 16 lines
I'm trying to read from a file and populate a stringgrid, and keep getting 'Project spares.exe raised an exception class 'External error: SIGSEGV' when trying to convert an integer to string. var {stockItem type is a record with the following structure: recordID : longint; ClassNumber : integer; PartNumber : string; Make : String; TypeofEqip : string; Model : string; Description : string; quantity : integer; location : string; price : real; }

Depending on the current compiler directive {$H+} (default for any lazarus program) type string will be ansistring.
If you write a record with a variable of type ansistring to file, it will write the pointer to that string.
If you read that file, this poiter probably will point to something you have no access to --> SIGSEV

Change all string explictely to ShortString in the definition of your record.

Bart

Reply by email