Solved

Making a simple descant of TMaskEdit

Posted on 1997-07-28
4
169 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now