[Solved] Is it possible to make "over-typecasting"? lazarus / 39-Graphics ---------------------------------------------------------------------- devEric69 · 2019-06-18 15:31 Hello, In Delphi, I was doing "over-typecasting" like this example....: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TDrawGrid(grdMyStringGrid).ColWidths[1]:= 650; ... because the property TStringGrid.ColWidths was protected - therefore impossible to modify - while the property TCustomDrawGrid.ColWidths (from which the TDrawGrid inherits) was published. Hence the "over-typecasting". The FPC compiler won't let me do this "trick": it tells me "TDBGrid and TDrawGrid are not related", which is true since they are on separate branches with a fork between the two (like their Delphi counterparts). Does anyone know if there is a compiler option, or better, something more encompassing like a compilation directive framing this line \ "trick", to bypass this constraint? ---------------------------------------------------------------------- Thaddy · 2019-06-18 15:34 This is possible in fpc too, but in this case the ancestors differ, so that's a problem. Valid casting can only be done on a strict hierarchy. I would consider this a design bug, you should report it. ---------------------------------------------------------------------- marcov · 2019-06-18 15:39 Compile in delphi mode ? But that it works in Delphi is sheer luck, fat chance that it only delivers a nice GPF. ---------------------------------------------------------------------- devEric69 · 2019-06-18 15:52 All right, good news. QuoteCompile in delphi mode ? But that it works in Delphi is sheer luck, fat chance that it only delivers a nice GPF. In fact, I just double-checked and I was wrong: in the Delphi VCL hierarchy, TStringGrid inherits directly from TDrawGrid (no fork in between), hence this possible trick. In the LCL, TStringGrid and TDrawGrid are on two distinct branches, with TCustomDrawGrid making the fork. ---------------------------------------------------------------------- wp · 2019-06-18 15:56 Quote from: devEric69 on June 18, 2019, 05:31:19 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TDrawGrid(grdMyStringGrid).ColWidths[1]:= 650; ... because the property TStringGrid.ColWidths was protected - therefore impossible to modify - while the property TCustomDrawGrid.ColWidths (from which the TDrawGrid inherits) was published. Hence the "over-typecasting". [...] "TDBGrid and TDrawGrid are not related" This desciption is a bit confusing... TStringGrid, TDrawGrid, TDBGrid? Which type is grdMyStringGrid? You probably only did not do the type- cast correctly. "ColWidths" is introduced as protected by the most elemental grid, TCustomGrid, from which all Lazarus grids are derived. ---------------------------------------------------------------------- devEric69 · 2019-06-18 16:02 I'm sorry. Indeed, I was wrong in my example which leads to confusion (I am the first one). grdMyStringGrid (my example uses a very bad "name") is, as the compiler tells me, a TDBGrid (which, in the VCL, is not at all on the same branch as TDrawGrid, TCustomGrid branching between the two in the VCL. But with Delphi "TDrawGrid(myDBGrid).Colwidths" compiles). Anyway, knowing what is possible or not now, I will do it differently with Lazarus. ---------------------------------------------------------------------- Thaddy · 2019-06-18 16:31 It's a matter of TCustomGrid --> TDrawgrid? Check the sources. ---------------------------------------------------------------------- devEric69 · 2019-06-18 16:54 I checked it out. My last post is correct: "TDrawGrid(myDBGrid).Col", for example, compiles with Delphi. I can give another example to overcome the level of visibility: "TLisbox (myBDListBox). a_property_that_becomes_visible" (myBDListBox is TDBListBox). But here, both are on the same branch in the Delphi VCL: they both inherit from TCustomListBox (appearanceally, it seams less "tricky", but it also allows you to bypass visibility). For information, I'm translating a Delphi program, into Lazarus. ---------------------------------------------------------------------- Thaddy · 2019-06-18 17:40 I already gave you the answer. ---------------------------------------------------------------------- devEric69 · 2019-07-15 17:24 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TDBGrid2 = class(TDBGrid)  private  protected  public    (* Redeclaration of properties with a change in visibility ,     to be able to modify the height of the rows ,     and width of the columns of a TDBGrid .*)    property RowHeights;     property ColWidths;  publishedend;