Forum > LCL

[RESOLVED] Is custom frame allowed?

(1/1)

egsuh:
Hello,

I'm thinking adding some methods to my custom frame.

Right now I have developed some frames descending TFrame, like


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type   TFrame1 = class(TFrame)    ....   end;     // in different file   TFrame2 = class(TFrame)   ...   end;  
Now I'd like to add new methods, procedure SayHello in this case. I' thinking rewriting as follows.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type   TMyFrame = class(TFrame)   public        procedure SayHello; virtual; abstract;    end;     Tframe1 = class(TMyFrame)    ....       procedure SayHello; override;    end;     // in different file that uses the unit containing TMyFrame definition.    TFrame2 = class(TMyFrame)   ...       procedure SayHello; override;    end;  
I tested this with one file, and it runs fine. I just want to confirm this approach is Okay.
Specifically I'm not registering TMyFrame, and just change the ancestor name.

   TFrame2 = class(TMyFrame)   // ==> Changing from TFrame to TMyFrame.

Is there no problem in doing this?

Thaddy:
Well, the registering has only impact on the designer.
If you want to have the new features available in the designer, you need to register the new frame.
In your case it is just a code extension, so not necessary, since it is only available from code and code completion will pick it up as well.

egsuh:
I found that this approach causes problems with .lfm files, when I re-open the project after closing.
It says some properties, e.g. designleft, taborder, etc. of the TmyFrame are not defined. Once I manually change .pas file (from TMyFrame to TFrame) the problems go away.

Thaddy:
Well in that case registering TMyFrame is a better option. Registering also means registering it for the streaming mechanism at design time.

egsuh:
It's been a while since last post here. But I think I'd better write my final (and good enough to now) solution.

I created a frame within the Lazarus IDE (File > New  > Frame), and then named it as 'myframe'. So the interface looks like


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TMyFrame = class(TFrame)public   procedure SayHello; virtual; abstract;  end;  
And then I changed all the frames which had been defined before I created TMyFrame as descendants of TMyFrame.
I just changed 'TFrame' after class to TMyFrame. 


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TFrame1 = class (TMyFrame)  // Originally it was     TFrame1 = class(TFrame)  ...   procedure SayHello; override; end;  
And then EVERYTHING is fine. I can add my own methods to TMyFrame, and make then virtual (and abstract).

What a great product Lazarus is !!!!!!   

Navigation

[0] Message Index

Go to full version