Solved

Making a simple descant of TMaskEdit

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 120
Show Listview image from database (String field) 5 123
Print Graphic and Text to Epson TM-T88v 12 245
How to Get Images From Server using App Tethering 11 21
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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