Recent

Author Topic: Custom Component : To create or not to create? That is the question.  (Read 1017 times)

TomTom

  • Full Member
  • ***
  • Posts: 108
Hi,
I think I need to create my own component based on TPageControl but not so sure of that ;)
I'm writing tabs based text editor and I think it would be convinient to add to TTabSheet few custom properties i.e. :

FileName for storing file name of TSynEdit placed on current tab
IsSaved for storing information about state of TSynEdit placed on TabSheet (was it saved or not)

and maybe few other properties in future:)

Or maybe there is other solution? I'm not sure if I have to create custom TPageControl component or custom TTabSheet (never tried to create custom components either from scratch or based on existing one). And how to connect this things?
Well, I've created custom TTabSheet and added to it mentioned above properties, it compiled and it was succesfully added to Component Palatte, but that is no use since I can't add TTabSheet alone to the form :P and I don't know how to test it.

How can I add my TMyTabSheet to TPageControl?

As I'm writing this post I'm also looking into TPageControl code. Now I think that I need to create TMyPageControl AND ALSO TMyTabSheet and add to TMyPageControl additional function AddMyTabSheet. Am I right?
Could anyone kindly point me what I need to look for? Or how to aproach this problem?

Bart

  • Hero Member
  • *****
  • Posts: 3355
    • Bart en Mariska's Webstek
Re: Custom Component : To create or not to create? That is the question.
« Reply #1 on: January 14, 2019, 02:33:31 pm »
I did write my own texteditor with a tabbed desing.
I did create a new component based on TPageControl, which has a property Filename...
I did override several methods and added some for my particular needs.
See: http://svn.code.sf.net/p/flyingsheep/code/trunk/EPlus/ and in particular the file editrrpagecontrol.pp there.

I use regular TTabSheets, because I needed no extra functionality from the TTabSheet, I simply create a TSynedit descendant on that with Align:=alClient, so that's all I needed and all the user sees.

Bart

lucamar

  • Hero Member
  • *****
  • Posts: 1046
Re: Custom Component : To create or not to create? That is the question.
« Reply #2 on: January 14, 2019, 03:11:55 pm »
I followed yet another route: I created a frame with a SynEdit control and put all the extras as fields/properties/methods of the frame. Then at runtime I create a frame for each new file whose parent is the corresponding (new) TTabSheet and access everything through it (up to and including loading files, saving them, search/replace, etc.). No subclassing at all (except for the TFrame, of course :) ).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/FPC 3.0.4 on:
(K)Ubuntu 12..16, Windows XP SP3 (Home/Prof.) and various DOS incarnations.

TomTom

  • Full Member
  • ***
  • Posts: 108
Re: Custom Component : To create or not to create? That is the question.
« Reply #3 on: January 14, 2019, 03:58:56 pm »
So I will need to get into this :). I think that now I need to create another small project to learn this things (overriding etc) ... oh man:P
I have only small/none experience in those matters :)
Thanks guys :)

lucamar

  • Hero Member
  • *****
  • Posts: 1046
Re: Custom Component : To create or not to create? That is the question.
« Reply #4 on: January 14, 2019, 04:59:08 pm »
So I will need to get into this :). I think that now I need to create another small project to learn this things (overriding etc) ... oh man:P
I have only small/none experience in those matters :)
Thanks guys :)

When I started with my editor (long, long ago ... with Delphi 1) it was a bare, simple Notepad replacement using TMemo. Then I started adding features as I needed them and some that looked cool and so on, writing small programs to test this or the other and all the while learning new and improved ways of doing something.

Now the program is a full-fledged editor-almost-IDE, I rebuilt it from scratch three times and I still keep changing and improving it as I learn new things and ways of doing things.

Everybody has to pass for this: it's the funny side of programming :)
« Last Edit: January 14, 2019, 05:02:10 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/FPC 3.0.4 on:
(K)Ubuntu 12..16, Windows XP SP3 (Home/Prof.) and various DOS incarnations.

TomTom

  • Full Member
  • ***
  • Posts: 108
Re: Custom Component : To create or not to create? That is the question.
« Reply #5 on: January 14, 2019, 08:02:04 pm »
EDIT
I was walking my dog a moment ago and came up with another idea. Maybe instead of adding properties for TPageControl I will add them to custom SynEdit. I think it will be good enough for my needs.  ::)
I Will try that tommorow:😀
EDIT2
Did it and it seems to work as I wanted. No fancy procedures or functions. Just a field/place to store information for individual SynEdit control :) It was even simpler than I thought. Ofcourse I still need to learn about adding functions/procedures overriding etc. for future but for now it will do :)

Code: [Select]
TKETEditor = class(TSynEdit)
    private
      FEFileName: String;
      FEFilePath: String;
    public
      property EFileName: String read FEFileName write FEFileName;
      property EFilePath: String read FEFilePath write FEFilePath;




...

When I started with my editor (long, long ago ... with Delphi 1) it was a bare, simple Notepad replacement using TMemo. Then I started adding features as I needed them and some that looked cool and so on, writing small programs to test this or the other and all the while learning new and improved ways of doing something.

Now the program is a full-fledged editor-almost-IDE, I rebuilt it from scratch three times and I still keep changing and improving it as I learn new things and ways of doing things.

Everybody has to pass for this: it's the funny side of programming :)

In a sense I've managed to find a walkaround of this problem without creating custom components but it's not efficient and it can generate errors, it's hard to keep track of what and when something is going on. So I thought I need to take different approach. Logically the best solution is to create custom TPageControl in conjunction with SynEdit like Bart. Then I'll have possibility to add this Component to other projects :)
So now I'll try to understand that.

And yes I agree that small projects are great for learning new things :) Now I'm working on 3rd version of my YATE Editor :P
« Last Edit: January 15, 2019, 11:18:48 am by TomTom »