-1

I'm making a descendant of TDBGrid. How can I declare a variable of type TDBGridInplaceEditor, since it is declared in the implementation part of the unit DBGrids?

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
DrWael
  • 247
  • 2
  • 12
  • Make a complete copy of the unit. Your prior question(s) should have already hinted at this. – Jerry Dodge Oct 28 '16 at 03:20
  • If you have read the comments on my prior question , you would know that your suggestion is discussed in detail , tested , and leads to dead end, due to class and unit dependencies. – DrWael Oct 28 '16 at 03:33
  • What I mean is create your own version of the control. Simply copying the unit is only the first step. If you really want the behavior of this control to be modified to your preference, then the only other option would be to go out and seek a third-party control. – Jerry Dodge Oct 28 '16 at 03:40
  • 2
    But in any case, your core question of accessing a class which is in the implementation of a VCL unit has already been proven to be impossible. Asking another question will not likely magically make it possible. Or were you expecting us to do all that custom code writing for you? – Jerry Dodge Oct 28 '16 at 03:41
  • Dear colleague , I'm making a third party dbgrid . For its picklist feature to work properly, I need to create an instance of type tdbgridinplaceeditor , which Borland may thought that no one will need to use this unique class, so they hide it in the implementation section of dbgrid, in a rare behaviour . – DrWael Oct 28 '16 at 03:47
  • Ok, you never and probably will not ever code any thing for me. If you do not like the question , do not bother your self to stop and comment and waste your time despite mine reading the just-general-speaking you typed. I'm discussing with experienced Delphi developer s who know how to do it , or know that it is impossible. B.t.w : I'm programming in Delphi for about 20 years now, which is probably longer than your age, so I do not want you to write any code for me. – DrWael Oct 28 '16 at 03:59
  • 1
    @Dr - Copying the unit does not work for you because you're using it in a package. It works in a stand-alone project, I tested. – Sertac Akyuz Oct 28 '16 at 04:04
  • 5
    If I did not like the question, I would have downvoted or voted to close. It is an interesting topic. However, just the fact that you are resorting to insults tells me (and everyone else here) that you have a lack of respect. Sure, I may not have been a developer for as long as you. But that type of attitude accomplishes nothing. – Jerry Dodge Oct 28 '16 at 04:05
  • @Sertac yes of course , it will be easier in a stand alone project, but the derived dbgrid is a member in a family of controls I make that share some common features . – DrWael Oct 28 '16 at 04:12
  • 3
    I'll mention it again. This particular question, regardless of your prior questions (which we shouldn't have to read), is simply answered by "it's not technically possible". You can't declare a variable of a class in the implementation of a VCL unit, or any other unit for that matter. Is that not what this question is asking? – Jerry Dodge Oct 28 '16 at 04:26
  • Let the grid create the editor, you can get a reference to the inplace editor by overriding CreateEditor, but your reference will be of type TInplaceEdit. Doesn't it help? Should your reference be exactly TGridInplaceEdit? – Sertac Akyuz Oct 28 '16 at 04:38
  • @Stack unfortunately , Tinplaceeditor do not support Picklist . for this reason , the standard dbgrid -wich is the ancestor - do not use this class, and instead the dbgrids unit defined the extended class tdbgridinplaceeditor . But in a rare situation, the Delphi team decided to declare this unique class in the implementation part of the unit . They may thought that no one will need it , but that decesion prevented subclasses of dbgrid from instantiate the extended inplace editor. :( – DrWael Oct 28 '16 at 04:49
  • 1
    I suggest again asking a question about the problem you are trying to solve. – Sertac Akyuz Oct 28 '16 at 12:55

1 Answers1

1

How can I declare a variable of type TDBGridInplaceEditor, since it is declared in the implementation part of the unit DBGrids?

You cannot.

In a comment you say:

that decision prevents subclasses of TDBGrid from instantiating the extended inplace editor

That is not true. You can call CreateEditor on your grid and obtain an instance of TDBGridInplaceEdit.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • but i did it already , and all i've got is [compiler error Undeclare identifire : 'TDBGridInplaceEdit'] , though i ofcourse used DBGrids . That what made search for the declaration of TDBGridInplaceEdit and found that it is in the implementation part. Can you tell me how you did it before ? – DrWael Oct 28 '16 at 13:22
  • 1
    The compile time type returned by `CreateEditor` is `TInplaceEdit`, but the actual instance returned has type `TDBGridInplaceEdit`. You declare your variable to be of type `TInplaceEdit`, and the code compiles. The actual instance behaves as `TDBGridInplaceEdit`, because that is what it is. – David Heffernan Oct 28 '16 at 13:28
  • Answering your question is easy enough. But what would be more helpful to you would be if you could only let us help you solve your problem. Why won't you tell us what your actual problem is? – David Heffernan Oct 28 '16 at 13:29
  • (1) the actual problem is : i'm subclassing TDBGrid. I created the editor using : function TWDBGrid.CreateEditor: TInplaceEdit; begin result:=TInplaceEdit.Create(self); end; then the grid do not show PickList or Ellipsis . so @Sertac Akyuz guided me that TInplaceEditor is the wrong editor, and i should use TDBGridInplaceEdit instead . i reviewd the delphi soure code of DBGrid and i found that DBGrid indeed used TDBGridInplaceEdit. so i took Sertack's advise and changed the CreateEditor to : (cont. ..) – DrWael Oct 28 '16 at 13:42
  • (2) function TWDBGrid.CreateEditor: TInplaceEdit; begin result:=TDBGridInplaceEdit.Create(self); end; but the compiler gives error [ Undeclared Identifier : "TDBGridInplaceEdit" ] so i reviewed DBgrids.pas again and discovered that TDBGridInplaceEdit is declared in the implementation . that is all :) – DrWael Oct 28 '16 at 13:44
  • You just need to slow down, think a little, and do exactly what I said in the answer. Create an instance of `TDBGridInplaceEdit` by calling `CreateEditor`. That's it. You can't refer to the type `TDBGridInplaceEdit`, but that doesn't matter. Your variable is of type `TInplaceEdit`, but at runtime the instance is of type `TDBGridInplaceEdit`. I've said this twice now. I won't say it again. – David Heffernan Oct 28 '16 at 13:46
  • your answer is clear enough from the first time , but what i'm saying to you is : no this is wrong. (1) in practice : i've made what you are saying 7 days ago and i keep testing for three days . the inplace editor is behaving as declared : TInplaceEditor. picklist and ellipse button will not show for eternity . – DrWael Oct 28 '16 at 13:58
  • (2) in theory : TDBGridInplaceEdit is a descendant of TInplaceEditList , which in turn is a descendant of TInPlaceEdit . an ancestor class can not behave like a descendant because it lakes the functionality , unless it is hardcasted. To be able to hardcast (or do any thing) , you have to use declared identifiers, or your code will not compile in the first place. and in our case , the descendant is only declared in local scope. – DrWael Oct 28 '16 at 14:00
  • (3) if you have a working example that proves your point of view , please reveal. – DrWael Oct 28 '16 at 14:00
  • 1
    @DrWael: Are you always this rude and confrontational with people who are trying to help you? – MartynA Oct 28 '16 at 14:02
  • @DrW - My suggestion was not `result:=TDBGridInplaceEdit.Create(self)` it was `result:=inherited CreateEditor`, then you'd have a `TDBGridInplaceEdit` object referenced as a `TInplaceEdit` in result. Which you can cast to a `TInplaceEditList` to access the pick list if you have to. What's the problem with that? – Sertac Akyuz Oct 28 '16 at 14:18
  • @SertacAkyuz thanks , i will test and return to you in 5 . But using this approach , were you able to use TDBGridInplaceEdit unique features like overrideing DropDown or so ? – DrWael Oct 28 '16 at 14:24
  • The code in my answer does exactly what I claim it does. It seems that you don't know the difference between compile time type and runtime type. Once you can understand that you'll make progress. – David Heffernan Oct 28 '16 at 14:26
  • 1
    @DrW - Can't tell, you never tell us what you are trying to achieve, do you? I never did try to override DropDown or such. – Sertac Akyuz Oct 28 '16 at 14:27
  • OK. I think cultural differences, especially in writing styles, and the nature of social networking basically as a non-vocal medium, prevent true communication here. I will pause the conversation since some conversation parties seem like considering some of my comments offensive, while it was written to be punctilious to remove ambiguity. But the expressions may differ from one nation to another, and I’m not an Englishman after all. For the record: @Sertac : your suggestion showed the arrow of the picklist at runtime, but the list did not drop down, though it is populated with items. – DrWael Oct 28 '16 at 14:51