Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How does one create a Delphi Editmask for M/F or F/P or Y/N?

Posted on 2008-06-10
12
Medium Priority
?
1,793 Views
Last Modified: 2012-06-21
I am using Delphi 7 and mysql 5.0 with MySQLDAC.
I am creating an app which uses a 3rd party component (DBPanelEdit) which automatically generates the edit controls based on the table fields.  I don't want to change the component code to handle Y/N, M/F and other one of two character inputs.  I have EE'd and googled TEDITMASK but have not found a way to mask this although I have found useful OnKeyPress and other events but again I would have to edit the components code and I really don't want to do that.

I know it is probably something simple but I can't spend any more time searching.

Thanks

John
0
Comment
Question by:ajtsoukalas
[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
  • 6
  • 4
  • 2
12 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 21752526
just by using the editmask, you can't. but you can use a mask of "L;1;_" (without quotes) and then then onkeypress event to make sure only your desired characters will be pressed
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 21753194
0
 

Author Comment

by:ajtsoukalas
ID: 21754575
Geert_Gruwez;

As I understand this website, I would still have to modify dbPanelEdit to add calls to tha component.  Is that accurate?

John
0
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!

 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 21757296
yeah, is there an OnValidate routine ?
Usually that's the place to put the test

like

procedure TForm1.OnValidate(Sender: TObject; EditText: string; var IsValid: boolean);
begin
  // true if string AInputString match regular expression ARegExpr
   // ! will raise exeption if syntax errors in ARegExpr
   IsValid := ExecRegExpr ('\d*', EditText);
  // test if EditText is all numbers
end;

Open in new window

0
 

Author Comment

by:ajtsoukalas
ID: 21833515
Thank you for your time but I as said in the original post that I didn't want to edit the component to accomplish this task.
It appears that I might have to consider it so I will give 100 points to each of you for your effort as I have already found examples to use for that.

AJ

0
 
LVL 28

Expert Comment

by:2266180
ID: 21833539
using events does not mean thaht you change the component. that is normal. s I don't see why you consider the above solutions as changing/edit the component....
0
 

Author Comment

by:ajtsoukalas
ID: 21833572
Correct me if I am wrong,
but because the Component creates its own edit controls, I would have have generalized code in each routine to handle the specific edit control.  As this would mean cycling through the objects on the form to find the right one, a better solution would be to modify the component directly would it not?

AJ
0
 
LVL 28

Expert Comment

by:2266180
ID: 21833679
no. in worse case scenario (if you don't wat to manually or dynamically assign the event (I dont' see any reasons why you would not want that)) you can alway subclass the control like:

type
  TCheckBox=class(stdctrls.TCheckBox)// use the same name here
    overwrite whatever methods you need here
  end;
0
 

Author Comment

by:ajtsoukalas
ID: 21833847
ciuly:
I'm sorry to be so dense, but I do not understand.
The panel component creates the edits dynamically based on the datasource.  If I use a form event, I don't necessarily know what edit control called that event unless I cycle though the form objects or use the sender field to determine what control was created.  If I have more than one 1of2 edit controls on the page, I would still have to figure out which one applies and what unique info it requires.  Wouldn't it be better to change the components edit control creation to add  the mask and event code in the edit control the panel creates?
0
 
LVL 28

Accepted Solution

by:
2266180 earned 2000 total points
ID: 21833999
>> use the sender field to determine what control was created
what's wrong with that? that's what the sender parameter is there for.

>>  Wouldn't it be better to change the components edit control creation to add  the mask and event code in the edit control the panel creates
no

I still don't understand why is it so hard to write

tform1=class(tform)
blabla
procedure mykeypress(sender:tobject; var key:char);
end;

and in the panel or whomever creates the checkbox:

edit:=tcheckbox.create(whatever);
edit.onkeypress:=mykeypress;
edit.editmask:='L;1;_';

blabla

it's really that simple.

you do not need to see what edit is this about as ALL edits use the SAME event and the SAME mask.

I don't understand what problems you have with this approach.
0
 

Author Comment

by:ajtsoukalas
ID: 21834256
ciuly:

Thanks
I will try your suggestion.

AJ
0
 

Author Closing Comment

by:ajtsoukalas
ID: 31465783
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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