Recent

Author Topic: Add method to component without package?  (Read 6412 times)

keithfre

  • New Member
  • *
  • Posts: 25
Add method to component without package?
« on: February 02, 2011, 07:17:45 pm »
Can I add a method to a component (TStringGrid) without compiling it into a package? Packages used to drive me nuts in Delphi, and they don't seem to have got any simpler in lazarus...

The method has no effect on the visual aspects of TStringGrid, all it does is populate the cells from my own TTabDelimitedStringList.
-Keith Freeman

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1931
Re: Add method to component without package?
« Reply #1 on: February 02, 2011, 09:12:06 pm »
Can I add a method to a component (TStringGrid) without compiling it into a package?

Sure, you can derive your own class from TStringGrid, but you will not be able to use it in the IDE designer/object-inspector unless you install it in the IDE (package).
You can create your object in code however.

keithfre

  • New Member
  • *
  • Posts: 25
Re: Add method to component without package?
« Reply #2 on: February 02, 2011, 09:19:26 pm »
Can I drop a TStringGrid onto my form, set its properties using the inspector, then just change TStringGrid to [name of my TStringGrid] in the code?
-Keith Freeman

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1931
Re: Add method to component without package?
« Reply #3 on: February 02, 2011, 09:33:38 pm »
Afaik no.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11036
  • Debugger - SynEdit - and more
    • wiki
Re: Add method to component without package?
« Reply #4 on: February 03, 2011, 12:32:51 am »
not sure, at least not in a comfortable way...

You could edit your code (the form declaration and all) AND edit the LFM (+ lfr if still using lfr)

But then you could probably no longer edit this form in the designer....

And you would still have to make sure the derived class is known to the stream loading system.
I thing "RegisterClass(YourGridClass)" in initialization....

Not sure if this is all, or if there is more....

But it's gonna be a hell worse than creating a new package

ik

  • Jr. Member
  • **
  • Posts: 88
  • ik
    • LINESIP
Re: Add method to component without package?
« Reply #5 on: February 03, 2011, 10:34:36 am »
Can I drop a TStringGrid onto my form, set its properties using the inspector, then just change TStringGrid to [name of my TStringGrid] in the code?


Yes and no. You can do it using IFDEF for example, that allow you to change the class type like so:

Code: Pascal  [Select][+][-]
  1. ...
  2. TForm1 = class(TForm)
  3. ...
  4. StringGrid1 : {$IFUNDEF INIDE}TStringGrid {$ELSE} TMyGrid {$ENDIF} ;
  5. ...

 

TinyPortal © 2005-2018