Ticket T980675
Visible to All Users

Error in the TcxGrid component, checkbox type field, OnGetPropertiesForEdit event

created 4 years ago (modified 4 years ago)

Hello, I'm having a problem in a routine using the TcxGrid component, the field and of the type CheckBox, in the OnGetPropertiesForEdit event. This error is occurring because delphi was updated from version 2010 to XE7, the version of DevEspress used and 17.1.6.

Code example

Delphi
procedure TF_SeloDigital_Selar.cxGrid1DBBandedTableView1STATUSGetPropertiesForEdit(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord; var AProperties: TcxCustomEditProperties); begin if (not(RxServicosBaixarDATASELAGEM.IsNull) or (Dados.COMBINA_SELOS_AUTOMATICO and (RxServicosBaixarTIPOPAIFILHO.AsInteger = 2))) then begin AProperties.ReadOnly := True; end else begin AProperties.ReadOnly := False; end; end;

The message that appears is just an Access violation, does not appear the details.

Comments (1)
DevExpress Support Team 4 years ago

    Hello Louder,

    Please use code brackets for your code. Thus, your code lines will be highlighted and your post will look more explicit.

    Answers approved by DevExpress Support

    created 4 years ago (modified 4 years ago)

    It is difficult to determine what objects are used from your code. It would be great if you add their descriptions or use designations:

    Delphi
    if (<Column1>.Index = 2) and (<Column2>.Index = 5) then ...

    I see that you try to modify the AProperties parameter of the OnGetPropertiesForEdit event handler. This is incorrect.
    I recommend you refer to the "TcxCustomGridTableItem.OnGetPropertiesForEdit Event" and "TcxCustomGridTableItem.OnGetProperties Event" help topics to read about our OnGetPropertiesForEdit and OnGetProperties events. There you will find absolutely the same situation as you faced:
    Clipboard-File-1.png

    As you can see, the correct way to accomplish your task is to create two RepositoryItems with different settings (one with ReadOnly = True, another one with ReadOnly = False) and set the AProperties parameter to the required RepositoryItem according to your conditions.

      Comments (2)

        The following change was made, including the cxEditRepository component and adding a checkbox type item, apparently the problem no longer occurs, the changed code is shown below.

        Delphi
        procedure TF_SeloDigital_Selar.cxGrid1DBBandedTableView1STATUSGetPropertiesForEdit(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord; var AProperties: TcxCustomEditProperties); begin if (not(RxServicosBaixarDATASELAGEM.IsNull) or (Dados.COMBINA_SELOS_AUTOMATICO and (RxServicosBaixarTIPOPAIFILHO.AsInteger = 2))) then begin cxEditRepository1CheckBoxItem1.Properties.ReadOnly := True; AProperties := cxEditRepository1CheckBoxItem1.Properties; end else begin cxEditRepository1CheckBoxItem1.Properties.ReadOnly := False; AProperties:= cxEditRepository1CheckBoxItem1.Properties; end; end;

        Thanks for the support Mikhail.

        DevExpress Support Team 4 years ago

          Please note that the correct way is to create and adjust several RepositoryItems in advance (for example, in the Form.OnCreate event handler or at design time) and only use the OnGetPropertiesForEdit event to vary in-place editors and not to adjust them. In this case, your code should look as follows:

          Delphi
          procedure TF_SeloDigital_Selar.FormCreate(Sender: TObject); begin cxEditRepository1CheckBoxItem1.Properties.ReadOnly := True; cxEditRepository1CheckBoxItem2.Properties.ReadOnly := False; end; procedure TF_SeloDigital_Selar.cxGrid1DBBandedTableView1STATUSGetPropertiesForEdit(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord; var AProperties: TcxCustomEditProperties); begin if (not(RxServicosBaixarDATASELAGEM.IsNull) or (Dados.COMBINA_SELOS_AUTOMATICO and (RxServicosBaixarTIPOPAIFILHO.AsInteger = 2))) then AProperties := cxEditRepository1CheckBoxItem1.Properties //ReadOnly = True else AProperties:= cxEditRepository1CheckBoxItem2.Properties; //ReadOnly = False end;

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.