Sign in Join

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

Mailing lists / lazarus / 2002-12

Possible bug in FPC or in Lazarus?

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Martin Smat
to Martin Smat: Look at the procedure TCustomListBox.CreateHandle: procedure TCustomListBox.CreateHandle;…
Mattias Gaertner wrote 59 lines
On Thu, 19 Dec 2002 18:51:07 +0100 Martin Smat wrote: >Hi, >Look at the procedure TCustomListBox.CreateHandle: > >procedure TCustomListBox.CreateHandle; >var > NewStrings : TStrings; > i: integer; >begin > inherited CreateHandle; > CNSendMessage(LM_SETBORDER, Self, nil); > UpdateSelectionMode; >(1) UpdateSorted; > NewStrings:= TStrings(Pointer(CNSendMessage(LM_GETITEMS, Self, nil))); > NewStrings.Assign(Items); > for i:=0 to Items.Count-1 do begin > if clbiSelected in GetListBoxItemRecord(FItems,i)^.Flags then > SendItemSelected(i,True); > end; > FItems.Free; > FItems:= NewStrings; > CNSendMessage(LM_SETITEMINDEX, Self, Pointer(FItemIndex)); >end; > >Line (1) UpdateSorted sends LM_SORT message which works with >TGtkCListStringList (in GTK) or with TWin32CListStringList (in Win32) >object. These classes are descendands of class TStringList. >In constructor TCustomListBox.Create is line >FItems := TExtendedStringList.Create(...). TExtendedString is descendand >of class TStringList too. >So we have folowing classes: > TStringList > | > |---TWin32CListStringList > | > |---TExtendedString > >When processing the LM_SORT message in interface, there is this >typecasting (symplified): > TWin32CListStringList(FItems).Sorted:=... >This line calls TWin32CListStringList.SetSorted method. > >On this line crashes the listboxtest.pp example. I think it is because >of calling the SetSorted method. This method is not in TExtendedString >class. >Listboxtest example ends with "Unknown Run-Time Error : 217". (tested in >Win32) UpdateSorted sent the wrong list in TLMSort. The gtk interface does not use it and so the bug didn't appear there. I fixed that. Can a win32 user check if this works? Mattias

Yes, it works now. Thanks.

Reply by email

Martin Smat

Hi,
Look at the procedure TCustomListBox.CreateHandle:

procedure TCustomListBox.CreateHandle;
var
   NewStrings : TStrings;
   i: integer;
begin
   inherited CreateHandle;
   CNSendMessage(LM_SETBORDER, Self, nil);
   UpdateSelectionMode;
(1)  UpdateSorted;
   NewStrings:= TStrings(Pointer(CNSendMessage(LM_GETITEMS, Self, nil)));
   NewStrings.Assign(Items);
   for i:=0 to Items.Count-1 do begin
     if clbiSelected in GetListBoxItemRecord(FItems,i)^.Flags then
       SendItemSelected(i,True);
   end;
   FItems.Free;
   FItems:= NewStrings;
   CNSendMessage(LM_SETITEMINDEX, Self, Pointer(FItemIndex));
end;

Line (1) UpdateSorted sends LM_SORT message which works with TGtkCListStringList (in GTK) or with TWin32CListStringList (in Win32) object. These classes are descendands of class TStringList. In constructor TCustomListBox.Create is line
FItems := TExtendedStringList.Create(...). TExtendedString is descendand of class TStringList too.
So we have folowing classes:
TStringList
|
|---TWin32CListStringList
|
|---TExtendedString

When processing the LM_SORT message in interface, there is this typecasting (symplified):

   TWin32CListStringList(FItems).Sorted:=...

This line calls TWin32CListStringList.SetSorted method.

On this line crashes the listboxtest.pp example. I think it is because of calling the SetSorted method. This method is not in TExtendedString class.
Listboxtest example ends with "Unknown Run-Time Error : 217". (tested in Win32)

If you still don't know what I'm speaking about compile my attached demo and run it. It ends with Run-Time error 216. I don't know why once it is error 216 and once 217. Maybe someone from FPC team can answer this.

Martin Smat.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: zip00007.zip
Type: application/octet-stream
Size: 371 bytes
Desc: "bugfpc.zip"
Url : http://localhost/pipermail/lazarus/attachments/20021219/a52abbf4/zip00007.obj

Reply by email

Unknown author
to Martin Smat
Martin Smat wrote 40 lines
Hi, Look at the procedure TCustomListBox.CreateHandle: procedure TCustomListBox.CreateHandle; var NewStrings : TStrings; i: integer; begin inherited CreateHandle; CNSendMessage(LM_SETBORDER, Self, nil); UpdateSelectionMode; (1) UpdateSorted; NewStrings:= TStrings(Pointer(CNSendMessage(LM_GETITEMS, Self, nil))); NewStrings.Assign(Items); for i:=0 to Items.Count-1 do begin if clbiSelected in GetListBoxItemRecord(FItems,i)^.Flags then SendItemSelected(i,True); end; FItems.Free; FItems:= NewStrings; CNSendMessage(LM_SETITEMINDEX, Self, Pointer(FItemIndex)); end; Line (1) UpdateSorted sends LM_SORT message which works with TGtkCListStringList (in GTK) or with TWin32CListStringList (in Win32) object. These classes are descendands of class TStringList. In constructor TCustomListBox.Create is line FItems := TExtendedStringList.Create(...). TExtendedString is descendand of class TStringList too. So we have folowing classes: TStringList | |---TWin32CListStringList | |---TExtendedString When processing the LM_SORT message in interface, there is this typecasting (symplified): TWin32CListStringList(FItems).Sorted:=... This line calls TWin32CListStringList.SetSorted method.

This is wrong, since TWin32CListStringList does not descend from TExtendedString.

What is more, based on what I think it should do, I think that TWin32CListStringList should not descend from TStringList but from TStrings.

Show quoted text 6 lines
On this line crashes the listboxtest.pp example. I think it is because of calling the SetSorted method. This method is not in TExtendedString class. Listboxtest example ends with "Unknown Run-Time Error : 217". (tested in Win32)

217 is an abstract error. It seems that some abstract method has not been properly implemented. Try compiling everything with version 1.1 of the compiler, it will tell you (warning/note) when a class containing an abstract method is constructed somewhere.

Michael.

Reply by email

Martin Smat
to Martin Smat: Look at the procedure TCustomListBox.CreateHandle: procedure TCustomListBox.CreateHandle;…
Martin Smat wrote 52 lines
Hi, Look at the procedure TCustomListBox.CreateHandle: procedure TCustomListBox.CreateHandle; var NewStrings : TStrings; i: integer; begin inherited CreateHandle; CNSendMessage(LM_SETBORDER, Self, nil); UpdateSelectionMode; (1) UpdateSorted; NewStrings:= TStrings(Pointer(CNSendMessage(LM_GETITEMS, Self, nil))); NewStrings.Assign(Items); for i:=0 to Items.Count-1 do begin if clbiSelected in GetListBoxItemRecord(FItems,i)^.Flags then SendItemSelected(i,True); end; FItems.Free; FItems:= NewStrings; CNSendMessage(LM_SETITEMINDEX, Self, Pointer(FItemIndex)); end; Line (1) UpdateSorted sends LM_SORT message which works with TGtkCListStringList (in GTK) or with TWin32CListStringList (in Win32) object. These classes are descendands of class TStringList. In constructor TCustomListBox.Create is line FItems := TExtendedStringList.Create(...). TExtendedString is descendand of class TStringList too. So we have folowing classes: TStringList | |---TWin32CListStringList | |---TExtendedString When processing the LM_SORT message in interface, there is this typecasting (symplified): TWin32CListStringList(FItems).Sorted:=... This line calls TWin32CListStringList.SetSorted method. On this line crashes the listboxtest.pp example. I think it is because of calling the SetSorted method. This method is not in TExtendedString class. Listboxtest example ends with "Unknown Run-Time Error : 217". (tested in Win32) If you still don't know what I'm speaking about compile my attached demo and run it. It ends with Run-Time error 216. I don't know why once it is error 216 and once 217. Maybe someone from FPC team can answer this. Martin Smat.

More info: After removing the keyword "virtual" in procedure TWin32CListStringList.SetSorted, the example runs fine.

Martin.

Reply by email

Mattias Gaertner
to Martin Smat: Look at the procedure TCustomListBox.CreateHandle: procedure TCustomListBox.CreateHandle;…
Show quoted text 46 lines
Hi, Look at the procedure TCustomListBox.CreateHandle: procedure TCustomListBox.CreateHandle; var NewStrings : TStrings; i: integer; begin inherited CreateHandle; CNSendMessage(LM_SETBORDER, Self, nil); UpdateSelectionMode; (1) UpdateSorted; NewStrings:= TStrings(Pointer(CNSendMessage(LM_GETITEMS, Self, nil))); NewStrings.Assign(Items); for i:=0 to Items.Count-1 do begin if clbiSelected in GetListBoxItemRecord(FItems,i)^.Flags then SendItemSelected(i,True); end; FItems.Free; FItems:= NewStrings; CNSendMessage(LM_SETITEMINDEX, Self, Pointer(FItemIndex)); end; Line (1) UpdateSorted sends LM_SORT message which works with TGtkCListStringList (in GTK) or with TWin32CListStringList (in Win32) object. These classes are descendands of class TStringList. In constructor TCustomListBox.Create is line FItems := TExtendedStringList.Create(...). TExtendedString is descendand of class TStringList too. So we have folowing classes: TStringList | |---TWin32CListStringList | |---TExtendedString When processing the LM_SORT message in interface, there is this typecasting (symplified): TWin32CListStringList(FItems).Sorted:=... This line calls TWin32CListStringList.SetSorted method. On this line crashes the listboxtest.pp example. I think it is because of calling the SetSorted method. This method is not in TExtendedString class. Listboxtest example ends with "Unknown Run-Time Error : 217". (tested in Win32)

UpdateSorted sent the wrong list in TLMSort. The gtk interface does not use it and so the bug didn't appear there. I fixed that. Can a win32 user check if this works?

Mattias

Show quoted text 7 lines
If you still don't know what I'm speaking about compile my attached demo and run it. It ends with Run-Time error 216. I don't know why once it is error 216 and once 217. Maybe someone from FPC team can answer this. Martin Smat.

Reply by email