Jump to content


Photo

Bug with Inheritance


  • Please log in to reply
5 replies to this topic

#1 Edipo Santos

Edipo Santos
  • Members
  • 3 posts
  • Location:RN / Brazil

Posted 31 October 2008 - 04:47 PM

Hello Boki

Today i've created one form using another as ancestor, but i've found two bugs in the component sad.gif

1.

In the ancestor i have one NextGrid with four columns, and in the children i will use only two of them.

But when i change the column's caption and width, it simply disappear from the form, like a crashed application.

I've attached a screen of the problem


2.

In the same form, if you try to delete a column that exists in the ancestor form, the component start a infinite loop and crash the whole Delphi, there is a screen attached to the topic too.


Sorry for bad english, hope it helps
Thanks!

Attached Files



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 31 October 2008 - 07:18 PM

Hello Edipo,

Unfortunatelly this is known bug and when Form is derrived it must not be changed by NextGrid.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 IVO GELOV

IVO GELOV
  • Members
  • 7 posts

Posted 28 April 2009 - 06:06 PM

This wrong behaviour is caused because grid columns are implemented as child controls of the grid, instead of being members of TCollection.
So, when you have for example a base form with NextGrid and 1 text column,
and derived form with a modified NextGrid - with 2 text columns, the result is:
1. DFM streaming sees that your form has ancestor and reads the components from base form - so NextGrid now has 1 child control (single column from ancestor)
2. DFM streaming continues with description of derived form - since it is modified from the ancestor one (1 additional column), DFM contains information about the 2 columns
3. TReader class updates properties for the first column and instantiates the 2nd column. This is actually accomplished in
procedure TNxCustomColumn.ReadState(Reader: TReader); in file Sources/NextGrid/NxColumns.pas
which in turn calls
FColumns.UpdatePositionList(Self);
and here is the bug:
CODE
procedure TNxColumns.UpdatePositionList(AColumn: TNxCustomColumn);
var
  i: Integer;
begin
  { note: this method shift column on right position }
  if FPositionItemsList.Count > 0 then
    for i := 0 to FPositionItemsList.Count - 1 do
    begin

              // ====== fix by IVO GELOV to support VFI ========
      if (AColumn.name<>'') and (AColumn.name = PositionItem[i].name) then
              begin
                PositionItem[i].Assign(AColumn);
                Exit;
              end;
              // ===================================

      if (AColumn.Position < PositionItem[i].Position) then
      begin
        FPositionItemsList.Insert(i, AColumn);
        Exit;
      end;
  end;
  FPositionItemsList.Add(AColumn);
end;

Without my fix - it makes fake columns and thus pissing off painting later on.

IMHO, columns would be better implemented as a Collection - like in the excellent TVirtualTree.

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 30 April 2009 - 01:26 AM

Hello Ivo,

Thank you,

I am not sure what this fix change, can you please give me more details.

Best regards and thangs
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 IVO GELOV

IVO GELOV
  • Members
  • 7 posts

Posted 30 April 2009 - 03:46 PM

Hi, Boki.
Okay, I will explain in more detail.
I have 2 forms. The 1st is defined like this:

CODE
object baseFirma: TbaseFirma
  Left = 224
  Top = 600
  Width = 455
  Height = 230
  Caption = 'baseFirma'
  Color = clBtnFace
  OldCreateOrder = False
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 13
  object baseGrid: TNextGrid
    Left = 0
    Top = 40
    Width = 447
    Height = 162
    Align = alBottom
    AppearanceOptions = [aoHighlightSlideCells]
    AutoScroll = True
    EnableVisualStyles = False
    HeaderStyle = hsOldStyle
    Options = [goDisableColumnMoving, goGrid, goHeader, goSelectFullRow]
    ReadOnly = True
    PopupMenu = TntPopupMenu1
    TabOrder = 5
    TabStop = True
    object colName: TNxTextColumn
      DefaultWidth = 445
      Font.Charset = RUSSIAN_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      Header.Caption = #1053#1072#1080#1084#1077#1085#1086#1074#1072#1085#1080#1077
      Options = [coAutoSize, coCanSort, coDisableMoving, coPublicUsing, coShowTextFitHint]
      ParentFont = False
      Position = 0
      Sorted = True
      SortType = stAlphabetic
      Width = 445
    end
  end
end


and the second one is defined like this:

CODE
inherited frmUser: TfrmUser
  Left = 297
  Top = 365
  Caption = #1057#1087#1080#1089#1098#1082' '#1089' '#1087#1086#1090#1088#1077#1073#1080#1090#1077#1083#1080#1090#1077
  PixelsPerInch = 96
  TextHeight = 13
  inherited baseGrid: TNextGrid
    inherited colName: TNxTextColumn
      DefaultWidth = 285
      Width = 285
    end
    object colRole: TNxTextColumn
      Header.Caption = #1044#1083#1098#1078#1085#1086#1089#1090
      MinWidth = 32
      Options = [coAutoSize, coCanSort, coDisableMoving, coPublicUsing, coShowTextFitHint]
      Position = 1
      SortType = stAlphabetic
    end
    object colActive: TNxCheckBoxColumn
      Alignment = taCenter
      DefaultWidth = 60
      Header.Caption = #1040#1082#1090#1080#1074#1077#1085
      Header.Alignment = taCenter
      MinWidth = 32
      Options = [coAutoSize, coDisableMoving, coPublicUsing]
      Position = 2
      SortType = stBoolean
    end
    object colUser: TNxTextColumn
      Header.Caption = 'Username'
      Position = 3
      SortType = stAlphabetic
      Visible = False
    end
    object colPass: TNxTextColumn
      Header.Caption = 'Password'
      Position = 4
      SortType = stAlphabetic
      Visible = False
    end
  end
end


Without the fix, we see this funny picture (Attached File  wrong.gif   10.87KB   5 downloads),
and with my fix applied - we see how it should look alike (Attached File  right.gif   9.12KB   4 downloads)

I hope this is already well described rolleyes.gif

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 27 May 2009 - 10:00 PM

Hello Ivo,

I have apply this fix and I hope that now all works fine. Thank you again.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users