Making a simple descant of TMaskEdit

I want to make a TMaskEdit descant.
I have a function CorrectField(Str : string): string;
that i would like to run on the Text-field every time the TNewMaskEdit-control is exited or it's Text-field is read.

Currently I ues a normal TMaskEdit and run CorrectField in an OnExit procedure for every TMaskEdit-control I have in my application.
I also make sure to do like this
Str1 := CorrectField(MaskEditX.Text)
every time I read the Text-field of a MaskEdit in my application.

It is these two simple things I would like to build into a new TNewMaskEdit-control.

Can anyone help me do that. I dont need the full code - some clues might be enough.

Thanx - Steff
steffAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StevenBCommented:
 Presuming that you know about inheriting and writing new components then your problem should be fairly easy to resolve.
  To run your function everytime the text field is read, you would be probably best to do this in the Read method of the textfield property.

  Declare something like:

  Private
    function GetFPropName:String;
 
  Published
    Property PropName : String read GetFPropName write FPropname;

{.......}

function GetFPropName:String;
begin
  result := CorrectField(FPropname);
end;

  (This is quite tricky to explain without a specific example, which I'll happily provide if needed (NB you could also write a SetFPropname method which runs the Correctfield function if needed))

  To run your function every time the OnExit event is triggered, simply override the Exit method of the original component. Remember to call inherited in your overridden method, and then perform any of your own processing. Again I'll provide an example if you want one.

  Hope this is a start.

  Steven.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
steffAuthor Commented:
The answer about the Exit-things is ok - except I guess I have to override the DoExit-methode (since there are no Exit-methode).

I dont understand the part about running CorrectField every time the Text-proberty is read. I might not have explained my problem good enough. I will try again.
My TNewMaskEdit-component inherites after TCustomMaskEdit (just like TMaskEdit does). The TCustomMaskEdit has a property called Text (string) which has a read-method called GetText. If I could I would like to just override GetText in the following way...

function GetText: string;
begin
  Result := CorrectField(inherited GetText);
end;

...but I cant do that since GetText is private. So I need another way to make sure that the Text-proberty is corrected just before it is handed to the end-user of the component when he tries to read it.

I cant understand the talk about declaring a new property PropName. How should that work. I know about declaring new properties and read- and write-methods ect., but I just cant figure out a simple way to get my Text-property (already declared property) problem to work.

Hope my problem is a little more clear now! :-)
Hope for some help.

Thanx - Steff
0
StevenBCommented:
Steff,

  Yes you should override DoExit, not Exit (My Mistake). The instruction I was trying to give for the other problem, is that you should declare your own property which uses the Text property to store its value. As I suspected, I've made a complete mess of explaining this, so here is an example, which might be easier to understand.


_________________________________________________________________
unit NewMaskEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask;

type
  TNewMaskEdit = class(TCustomMaskEdit)
  private
    Function GetSpecialText:String;
    Procedure SetSpecialText(Aval:String);
  protected
    procedure DoExit; override;
  published
    property SpecialText : String read GetSpecialText write SetSpecialText;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Stevens Components', [TNewMaskEdit]);
end;

procedure TNewMaskEdit.DoExit;
begin
  inherited;
  // Perform any operations here which are triggered on the exit
end;

Function TNewMaskEdit.GetSpecialText:String;
var
  TempStr : String;
begin
  TempStr := Text;
  // Perform any operations on TempStr that you require here
  result := TempStr;
end;

Procedure TNewMaskEdit.SetSpecialText(Aval:String);
begin
  // The content of AVal can be altered here before it is assigned to Text
  Text := Aval;
end;

end.
_________________________________________________________________


  I hope this clears things up a little. If you've any more queries then plase ask.

  Steven.
0
steffAuthor Commented:
Your answer is fine. I solved the problem myself just before getting online to read your last comment.
I did something very close to what you now suggests - I just called the new property Text (like the old one) and used "inherited Text" from inside its read- and write-methods.
I didnt know that you could declare a new property with a name already used by your class-parent and then use "inherited Text" to get to the parents property - but I seems that you can.
I all works fine now - thanx for your help.

Steff
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.