How do I create a new type (sub-class) of textedit field?

[h]How do I create a new type (sub-class) of textedit field?[/h]
I use textedit fields for input, and several of them require uppercase only. Using the uppercase mask (>) on each works fine, but instead of entering that on every field, is there a way I can create a new type of field that always has the uppercase mask (that’s the only change) and use it as the super for all of these fields without having to enter the mask multiple time? Thanks in advance for help.

Create a new class
Set its super to be TextField
Then set the ones you’ve used to be instances of that (change their supers)

I hate to be dense, but…
I created a new class, it is automatically called class1. I would like to call it ‘uppertext’ but can’t find how to do that.
It asks for interfaces, so I checked DataCell. Seems logical, but no instructions.
I need to bring up ‘class1, uppertext’ and define its mask. Can’t find where to do that.
Last, I need to create new field called ‘CompName’ and make ‘uppertext’ its super. Where?
Thanks in advance for help

  1. Create a new class
  2. In the Inspector change “Class1” to “UpperText” [personally I’d suggest something like “TE_Upper” or “TextEdit_Upper”]
  3. change SUPER from BLANK to “TextEdit”
  4. leave Interfaces alone (do not change anything)
  5. Add a KeyDOWN event to the class you just created… adding this code
key=key.uppercase

Instead of placing TextEdit controls… place your new “UpperText” control instead
If you already have TextEdit controls… select each one and change ITS “Super” from “TextEdit” to “UpperText”

UpperText is whatever you actually used in step #2 above.

That is all there is to creating a “simple” custom control based on an existing one. Obviously you can do a lot more… but start slowly :slight_smile:

[quote=79439:@Dave S]Add a KeyDOWN event to the class you just created… adding this code
key=key.uppercase
[/quote]

It does not work. Seems key is read-only.

I got the desired result by adding the TextChange event with the code :

Me.Text = Me.Text.Uppercase

However, your description of custom class is an excellent how-to :slight_smile:

Michel - where did you add your code?
When I right click on my newly created class and select “Add new event handler” - there is noTextChange event listed?

The subclass has no event by itself.

You add the event to the original class. Then when you place a subclass on your window, it behaves like the original.

Or maybe you see a list of events but not TextChange because you need to scroll down in the list …

Oh my god - I can’t even get the simplest things to work! :frowning:

  1. I started a completely new project
  2. Created a new class
  3. In the Inspector I changed “Class1” to “UpperText”
  4. I then changed it’s SUPER from BLANK to “TextEdit”

THEN I GOT LOST !
What original class? All I have is 1 empty window and the new class which I just created???

HELP :frowning: :frowning: :frowning:

@Richard Summers You may need to work your way through the users guide :slight_smile:

Here is a link to a sample project that has a TextField subclass similar to the one Michel described.

The class you just created is what I call the original class. Here is what you do now :

  • Right click on UpperText, select Add to UpperText, then Add Event
  • Select TextChange
  • In TextChange, enter Me.Text = Me.Text.Uppercase

Now your class is available to be added to your window, except instead of getting it from the library, you will need to drag and drop it from the project. When you click on UpperText, drag and drop it onto your window, it creates a subclass called UpperText1 which has the uppercase behavior by default.

Got it working, but had to change one of Dave’s steps.

I had to set it’s super to TextEdit>TextField as opposed to just TextEdit
Thought I was going mad for a moment!

Now that is all working fine, I have another question:

Is it possible to create a few different subclasses and store them somewhere in the IDE, where they are always available to all projects Otherwise, I am guessing I have to create a blank project, store all my subclasses in that project, and then drag them all into my actual project file which I am working on?

Export them… this will create a file that can them be IMPORTED into a new project

but your idea of a storage “project” will work too

Thanks Dave.
I presume that it is sensible to break them down into groups, as opposed to 1 exported file containing all of the subclasses.
Otherwise the file size of my project will be increased unnecessarily - is that correct?

Depends on how you want to manage them.

If you use EXPORT, then each custom class is a file of its own, and you can use the operating system file management to organize them

If you store them in a special XOJO project, the you can organize them that way (and who care how big THAT project gets)… just copy and paste between that project file, and you new project file.

Thank you Dave - I am learning quite a lot lately by asking weird questions :slight_smile:

Also, I know its off-topic but how is your pdf thingymajig coming along?

If you put them all in a project, you can set that project up as a template and use it to start future projects so you have everything at hand to begin with. No copying or importing.

That makes sense - although I would imagine that if you had a lot of subclasses, you would have to then go through the entire project file and work out which subclasses you have not used, and then delete them - (in order to keep the file size of your compiled .exe down) ?

Or is that not an issue?
In other words - are unused subclasses still added to the compiled .exe?

[quote=79468:@Richard Summers]That makes sense - although I would imagine that if you had a lot of subclasses, you would have to then go through the entire project file and work out which subclasses you have not used, and then delete them - (in order to keep the file size of your compiled .exe down) ?

Or is that not an issue?
In other words - are unused subclasses still added to the compiled .exe?[/quote]
Stripped out if unused

[quote=79457:@Richard Summers]Got it working, but had to change one of Dave’s steps.

I had to set it’s super to TextEdit>TextField as opposed to just TextEdit
Thought I was going mad for a moment![/quote]

There is another way : drag the EditField from the library to the project (not the window). This saves you to have to create a class and set the super.