Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Access violation in IDE 10.2 when "F12" on a XE3 form with TCustomDrawGrid


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Feb 13, 2018 9:39 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Arnaud CHÂTELET

Posts: 3
Registered: 4/6/13
Access violation in IDE 10.2 when "F12" on a XE3 form with TCustomDrawGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 19, 2018 2:53 AM
I am opening in C++ Builder 10.2.2 forms which I have created with C++ Builder XE3.
When toggling from Unit to Form view (with F12 and Alt+F12), the IDE throws an Access Violation.
(Below are the details of theses AV.)
Access violation coming from :
- Vcl.Graphics.TBrush.SetData (Line 3396, "Vcl.Graphics.pas" + 5) + $3
- Vcl.Graphics.TGraphicsObject.Unlock (Line 2321, "Vcl.Graphics.pas" + 4) + $1
Both called by Vcl.Themes.TUxThemeStyle.DoDrawElement.

This happens only on forms containing grids derivated from TCustomDrawGrid and having one of the three events :
OnDrawCell
OnDrawCellTitle
OnGetCell
OnGetCellTitle

affected to following methods:
GridExpenseDrawCell
GridExpenseDrawCellTitle
GridExpenseGetCell
GridExpenseGetCellTitle

Here are extracts from my classes derivated from TCustomDrawGrid:

enum TMyGridColType {myTextAlignLeft, myTextAlignCenter, ...};

typedef void __fastcall (__closure TGetCellTitleEvent)(System::TObject Sender, int ACol, int ARow, WideString &AText, TMyGridColType &AColType);
typedef void __fastcall (__closure TGetCellEvent)(System::TObject Sender, int ACol, int ARow, WideString &AText, TMyGridColType &AColType);
typedef void __fastcall (__closure TDrawCellTitleEvent)(System::TObject Sender, int ACol, int ARow, const TRect &Rect, TGridDrawState State);

class PACKAGE TMyStringGrid : public TMyDrawGrid
{
private:
TDrawCellTitleEvent FOnDrawCellTitle;
TGetCellTitleEvent FOnGetCellTitle;
TGetCellEvent FOnGetCell;
protected:
void __fastcall DrawCell(int ACol, int ARow, const TRect &ARect, TGridDrawState AState);
__published:
//---Propriétés
__property TDrawCellTitleEvent OnDrawCellTitle = {read=FOnDrawCellTitle, write=FOnDrawCellTitle};
__property TGetCellTitleEvent OnGetCellTitle = {read=FOnGetCellTitle, write=FOnGetCellTitle};
__property TGetCellEvent OnGetCell = {read=FOnGetCell, write=FOnGetCell};
}

class PACKAGE TMyDrawGrid : public TCustomDrawGrid
{
protected:
virtual void __fastcall DrawCell(int ACol, int ARow, const System::Types::TRect &ARect, TGridDrawState AState);
__published:
//---Evénements
__property OnDrawCell;
}

And extracts from Vcl.Grids.hpp:
228 typedef void __fastcall (__closure TDrawCellEvent)(System::TObject Sender, int ACol, int ARow, const System::Types::TRect &Rect, TGridDrawState State);
445 virtual void __fastcall DrawCell(int ACol, int ARow, const System::Types::TRect &ARect, TGridDrawState AState) = 0 ;

540 class PASCALIMPLEMENTATION TCustomDrawGrid : public TCustomGrid
{
typedef TCustomGrid inherited;
private:
TDrawCellEvent FOnDrawCell;
protected:
560 virtual void __fastcall DrawCell(int ACol, int ARow, const System::Types::TRect &ARect, TGridDrawState AState);
568 __property TDrawCellEvent OnDrawCell = {read=FOnDrawCell, write=FOnDrawCell};
}

The detail of the access violation is attached to [ the report I sent in Quality Central|http://qc.embarcadero.com/wc/qcmain.aspx?d=143370].
Here are the details for two forms:

First form:
(FFFFF056){bds.exe } [00000056]
[50AA007B]{vcl250.bpl } Vcl.Graphics.TBrush.SetData (Line 3396, "Vcl.Graphics.pas" + 5) + $3
(0002C63B){mycomponents2017.bpl} [2321D63B]
(0002C1D8){mycomponents2017.bpl} [2321D1D8]
[50BB21E8]{vcl250.bpl } Vcl.Themes.TUxThemeStyle.DoDrawElement (Line 2865, "Vcl.Themes.pas" + 5) + $25
[50BB1926]{vcl250.bpl } Vcl.Themes.TCustomStyleServices.DrawElement (Line 2561, "Vcl.Themes.pas" + 1) + $D
[50C274CF]{vcl250.bpl } Vcl.Grids.DrawCells (Line 2317, "Vcl.Grids.pas" + 48) + $12
[50C27E77]{vcl250.bpl } Vcl.Grids.TCustomGrid.Paint (Line 2496, "Vcl.Grids.pas" + 125) + $2F
[50AA1302]{vcl250.bpl } Vcl.Graphics.TCanvas.SetPenPos (Line 4143, "Vcl.Graphics.pas" + 1) + $9
[50ACFC2F]{vcl250.bpl } Vcl.Controls.TCustomControl.PaintWindow (Line 14142, "Vcl.Controls.pas" + 6) + $5
[50AC99C5]{vcl250.bpl } Vcl.Controls.TWinControl.PaintHandler (Line 10281, "Vcl.Controls.pas" + 4) + $14
[500605B7]{rtl250.bpl } System.TMonitor.Exit (Line 18719, "System.pas" + 2) + $7
[50ACA1B4]{vcl250.bpl } Vcl.Controls.TWinControl.WMPaint (Line 10482, "Vcl.Controls.pas" + 6) + $5
[50067898]{rtl250.bpl } System.@IntfClear (Line 37236, "System.pas" + 10) + $0
[525C0DAE]{vcldesigner250.bpl} VCLSurface.TVclDesignSurface.IsDesignMsg (Line 3656, "VCLSurface.pas" + 186) + $28
[50ACA1A7]{vcl250.bpl } Vcl.Controls.TWinControl.WMPaint (Line 10480, "Vcl.Controls.pas" + 4) + $7
[525C0DAE]{vcldesigner250.bpl} VCLSurface.TVclDesignSurface.IsDesignMsg (Line 3656, "VCLSurface.pas" + 186) + $28
[50ACFBC9]{vcl250.bpl } Vcl.Controls.TCustomControl.WMPaint (Line 14131, "Vcl.Controls.pas" + 2) + $4
[50AC4C16]{vcl250.bpl } Vcl.Controls.TControl.WndProc (Line 7326, "Vcl.Controls.pas" + 91) + $6
[5005FD9F]{rtl250.bpl } System.TObject.Dispatch (Line 17809, "System.pas" + 11) + $0
[50AC4C16]{vcl250.bpl } Vcl.Controls.TControl.WndProc (Line 7326, "Vcl.Controls.pas" + 91) + $6
[50067898]{rtl250.bpl } System.@IntfClear (Line 37236, "System.pas" + 10) + $0
[525C0DAE]{vcldesigner250.bpl} VCLSurface.TVclDesignSurface.IsDesignMsg (Line 3656, "VCLSurface.pas" + 186) + $28
[0B6AC244]{IDEFixPack.dll} VCLDesignerGuideLinesHideFix.IsDesignMsg (Line 76, "VCLDesignerGuideLinesHideFix.pas" + 25) + $6
[50AC499B]{vcl250.bpl } Vcl.Controls.TControl.WndProc (Line 7239, "Vcl.Controls.pas" + 4) + $21
[50AC97FB]{vcl250.bpl } Vcl.Controls.TWinControl.WndProc (Line 10197, "Vcl.Controls.pas" + 166) + $6
[5006085F]{rtl250.bpl } System.TMonitor.TryEnter (Line 18923, "System.pas" + 1) + $0
[500603D8]{rtl250.bpl } System.TMonitor.Enter (Line 18593, "System.pas" + 4) + $2
[50060258]{rtl250.bpl } System.TMonitor.CheckOwningThread (Line 18507, "System.pas" + 2) + $0
[50AC97FB]{vcl250.bpl } Vcl.Controls.TWinControl.WndProc (Line 10197, "Vcl.Controls.pas" + 166) + $6
[50C080B5]{vcl250.bpl } Vcl.Forms.TCustomForm.WndProc (Line 4546, "Vcl.Forms.pas" + 209) + $5
[50AC97FB]{vcl250.bpl } Vcl.Controls.TWinControl.WndProc (Line 10197, "Vcl.Controls.pas" + 166) + $6
[500603D8]{rtl250.bpl } System.TMonitor.Enter (Line 18593, "System.pas" + 4) + $2
(0000A084){mycomponents2017.bpl} [231FB084]
[50AC8DC8]{vcl250.bpl } Vcl.Controls.TWinControl.MainWndProc (Line 9896, "Vcl.Controls.pas" + 3) + $6
[5016EBC4]{rtl250.bpl } System.Classes.StdWndProc (Line 17406, "System.Classes.pas" + 9) + $2
[50C11A6F]{vcl250.bpl } Vcl.Forms.TApplication.ProcessMessage (Line 10613, "Vcl.Forms.pas" + 23) + $1
[50C11AB2]{vcl250.bpl } Vcl.Forms.TApplication.HandleMessage (Line 10643, "Vcl.Forms.pas" + 1) + $4
[50C11DE5]{vcl250.bpl } Vcl.Forms.TApplication.Run (Line 10781, "Vcl.Forms.pas" + 26) + $3
[005088E2]{bds.exe } bds.bds (Line 212, "" + 7) + $7

Second form:
(FFFFF046){bds.exe } [00000046]
[50A9EE28]{vcl250.bpl } Vcl.Graphics.TGraphicsObject.Unlock (Line 2321, "Vcl.Graphics.pas" + 4) + $1
(0002C63B){mycomponents2017.bpl} [076ED63B]
(0002C1D8){mycomponents2017.bpl} [076ED1D8]
[50BB21E8]{vcl250.bpl } Vcl.Themes.TUxThemeStyle.DoDrawElement (Line 2865, "Vcl.Themes.pas" + 5) + $25
[50BB1926]{vcl250.bpl } Vcl.Themes.TCustomStyleServices.DrawElement (Line 2561, "Vcl.Themes.pas" + 1) + $D
[50C274CF]{vcl250.bpl } Vcl.Grids.DrawCells (Line 2317, "Vcl.Grids.pas" + 48) + $12
[50C27E77]{vcl250.bpl } Vcl.Grids.TCustomGrid.Paint (Line 2496, "Vcl.Grids.pas" + 125) + $2F
[50AA1302]{vcl250.bpl } Vcl.Graphics.TCanvas.SetPenPos (Line 4143, "Vcl.Graphics.pas" + 1) + $9
[50ACFC2F]{vcl250.bpl } Vcl.Controls.TCustomControl.PaintWindow (Line 14142, "Vcl.Controls.pas" + 6) + $5
[50AC99C5]{vcl250.bpl } Vcl.Controls.TWinControl.PaintHandler (Line 10281, "Vcl.Controls.pas" + 4) + $14
[500605B7]{rtl250.bpl } System.TMonitor.Exit (Line 18719, "System.pas" + 2) + $7
[50ACA1B4]{vcl250.bpl } Vcl.Controls.TWinControl.WMPaint (Line 10482, "Vcl.Controls.pas" + 6) + $5
[50067898]{rtl250.bpl } System.@IntfClear (Line 37236, "System.pas" + 10) + $0
[525C0DAE]{vcldesigner250.bpl} VCLSurface.TVclDesignSurface.IsDesignMsg (Line 3656, "VCLSurface.pas" + 186) + $28
[50ACFBC9]{vcl250.bpl } Vcl.Controls.TCustomControl.WMPaint (Line 14131, "Vcl.Controls.pas" + 2) + $4
[50AC4C16]{vcl250.bpl } Vcl.Controls.TControl.WndProc (Line 7326, "Vcl.Controls.pas" + 91) + $6
[50ACFBC9]{vcl250.bpl } Vcl.Controls.TCustomControl.WMPaint (Line 14131, "Vcl.Controls.pas" + 2) + $4
[50AC4C16]{vcl250.bpl } Vcl.Controls.TControl.WndProc (Line 7326, "Vcl.Controls.pas" + 91) + $6
[500B0C8F]{rtl250.bpl } System.Variants.VarClearDeep (Line 839, "System.Variants.pas" + 3) + $1
[500B0D25]{rtl250.bpl } System.Variants.@VarClear (Line 886, "System.Variants.pas" + 3) + $0
[500B0D2D]{rtl250.bpl } System.Variants.@VarClr (Line 905, "System.Variants.pas" + 1) + $0
[50AC97FB]{vcl250.bpl } Vcl.Controls.TWinControl.WndProc (Line 10197, "Vcl.Controls.pas" + 166) + $6
(0000A084){mycomponents2017.bpl} [076CB084]
[50AC8DC8]{vcl250.bpl } Vcl.Controls.TWinControl.MainWndProc (Line 9896, "Vcl.Controls.pas" + 3) + $6
[5016EBC4]{rtl250.bpl } System.Classes.StdWndProc (Line 17406, "System.Classes.pas" + 9) + $2
[50ACC781]{vcl250.bpl } Vcl.Controls.TWinControl.Update (Line 12244, "Vcl.Controls.pas" + 1) + $12
[525BCEB8]{vcldesigner250.bpl} VCLSurface.TGrabHandles.Hide (Line 2107, "VCLSurface.pas" + 9) + $5
[525BCF09]{vcldesigner250.bpl} VCLSurface.TGrabHandles.SetSelection (Line 2125, "VCLSurface.pas" + 3) + $2
[211BFA51]{designide250.bpl} Designer.TDesigner.DragBegin (Line 860, "Designer.pas" + 1) + $7
[211C04E1]{designide250.bpl} Designer.TDesigner.ForceCommonSelectParent (Line 1096, "Designer.pas" + 4) + $1B
[211C264F]{designide250.bpl} Designer.TDesigner.MouseDown (Line 1760, "Designer.pas" + 86) + $9
[525BFCCF]{vcldesigner250.bpl} VCLSurface.MouseEvent (Line 3248, "VCLSurface.pas" + 36) + $2A
[500605B7]{rtl250.bpl } System.TMonitor.Exit (Line 18719, "System.pas" + 2) + $7
[525C090B]{vcldesigner250.bpl} VCLSurface.TVclDesignSurface.IsDesignMsg (Line 3518, "VCLSurface.pas" + 48) + $6
[0B6AC244]{IDEFixPack.dll} VCLDesignerGuideLinesHideFix.IsDesignMsg (Line 76, "VCLDesignerGuideLinesHideFix.pas" + 25) + $6
[50AC499B]{vcl250.bpl } Vcl.Controls.TControl.WndProc (Line 7239, "Vcl.Controls.pas" + 4) + $21
[09AB5188]{TrackingSystem250.bpl} TrackingSystemHelp.CBTHookProc (Line 211, "TrackingSystemHelp.pas" + 27) + $F
[50AC9009]{vcl250.bpl } Vcl.Controls.TWinControl.IsControlMouseMsg (Line 9960, "Vcl.Controls.pas" + 9) + $2A
[50AC97FB]{vcl250.bpl } Vcl.Controls.TWinControl.WndProc (Line 10197, "Vcl.Controls.pas" + 166) + $6
(0000A084){mycomponents2017.bpl} [076CB084]
[50AC8DC8]{vcl250.bpl } Vcl.Controls.TWinControl.MainWndProc (Line 9896, "Vcl.Controls.pas" + 3) + $6
[5016EBC4]{rtl250.bpl } System.Classes.StdWndProc (Line 17406, "System.Classes.pas" + 9) + $2
[50C11A6F]{vcl250.bpl } Vcl.Forms.TApplication.ProcessMessage (Line 10613, "Vcl.Forms.pas" + 23) + $1
[50C11AB2]{vcl250.bpl } Vcl.Forms.TApplication.HandleMessage (Line 10643, "Vcl.Forms.pas" + 1) + $4
[50C11DE5]{vcl250.bpl } Vcl.Forms.TApplication.Run (Line 10781, "Vcl.Forms.pas" + 26) + $3
[005088E2]{bds.exe } bds.bds (Line 212, "" + 7) + $7

What is causing the access violation?
Arnaud CHÂTELET

Posts: 3
Registered: 4/6/13
Re: Access violation in IDE 10.2 when "F12" on a XE3 form with TCustomDrawGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2018 1:51 AM   in response to: Arnaud CHÂTELET in response to: Arnaud CHÂTELET
I did not find yet a proper explanation but :
I removed the const before "TRect &ARect" in the DrawCell method declaration and implementation in my derived class.

I use CLang compiler in Embarcadero 10.2.
What is surprising is that Vcl.Grids.hpp contains :
typedef void __fastcall (__closure TDrawCellEvent)(System::TObject Sender, int ACol, int ARow, const System::Types::TRect &Rect, TGridDrawState State);
virtual void __fastcall DrawCell(int ACol, int ARow, const System::Types::TRect &ARect, TGridDrawState AState);

And in the pascal source file :
TDrawCellEvent = procedure (Sender: TObject; ACol, ARow: Longint; Rect: TRect; State: TGridDrawState) of object;
[...]
TCustomGrid = class(TCustomControl)
protected
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); virtual; abstract;
[...]
TCustomDrawGrid = class(TCustomGrid)
private
FOnDrawCell: TDrawCellEvent;
protected
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
property OnDrawCell: TDrawCellEvent read FOnDrawCell write FOnDrawCell;

As documented here:
[http://docwiki.embarcadero.com/Libraries/Berlin/en/Vcl.Grids.TCustomDrawGrid.DrawCell|http://docwiki.embarcadero.com/Libraries/Berlin/en/Vcl.Grids.TCustomDrawGrid.DrawCell]

Just a remark : the solution for me with CLang compiler in Embarcadero 10.2 is the exact opposite of the solution presented ... ten years ago ... (seems to be BCB6 borland former compiler) in messages #5 and #6 here:
[https://www.developpez.net/forums/d526638/c-cpp/outils-c-cpp/cppbuilder/probleme-ondrawcell-dynamique/|https://www.developpez.net/forums/d526638/c-cpp/outils-c-cpp/cppbuilder/probleme-ondrawcell-dynamique/]

The .hpp file was generated by my compiler DCC32 as explained here:
[http://edn.embarcadero.com/cs/article/26607|http://edn.embarcadero.com/cs/article/26607]

My question:
why does it work for me with simple reference "TRect &Rect" whereas the .hpp uses a const reference ?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Access violation in IDE 10.2 when "F12" on a XE3 form with TCustomDrawGrid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2018 9:39 AM   in response to: Arnaud CHÂTELET in response to: Arnaud CHÂTELET
Arnaud CHÂTELET wrote:

why does it work for me with simple reference "TRect &Rect" whereas
the .hpp uses a const reference ?

As you noted, in the Vcl.Grids.pas source code, the ARect parameter of
DrawCell() is not declared as 'const' to begin with, but is declared as
'const' in the generated Vcl.Grids.hpp file. It really shouldn't be
'const'. But because the TRect is being passed by value on the Pascal
side, and records more than a few bytes in size are actually passed by
(hidden) reference, the Delphi compiler translates that into a const
reference on the C++ side. Why 'const', I don't know.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02