?
Solved

Making a simple descant of TMaskEdit

Posted on 1997-07-28
4
Medium Priority
?
177 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 300 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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