Solved

Making a simple descant of TMaskEdit

Posted on 1997-07-28
4
175 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:steff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
StevenB earned 100 total points
ID: 1340080
 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
 

Author Comment

by:steff
ID: 1340081
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
 
LVL 4

Expert Comment

by:StevenB
ID: 1340082
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
 

Author Comment

by:steff
ID: 1340083
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question