Solved

Delphi Programming Question

Posted on 1997-09-29
5
162 Views
Last Modified: 2010-04-04
I want to capitalize the first letter of each word entered in a comboxbox - while the user types.  I don't want to do it on exit so I know I have to catch the keystroke, I just don't know how to just capitaize the first letter only using one of the 'Upper' functions.

Secondly, the Delphi manaual says to use the Abort procedure to cancel Post actions if used in the BeforePost event.  I get a compile error when I try - if "if edit1.text = '' then abort;" and "Statement expected, but expression of type 'Integer' found.  What is the correct syntax?
0
Comment
Question by:d4jaj1
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1346451
Hi d4jaj1,

Q1 :

procedure TForm1.ComboBox1Change(Sender: TObject);
var HelpStr : String;
begin
 if ComboBox1.GetTextLen = 1 then
  begin
   HelpStr := UpperCase(ComboBox1.text[1]);
   ComboBox1.Text := HelpStr;
   ActiveControl := ComboBox1;
  end;
end;

But that's not all, because now the cursor is back in the beginning of the line. You need a SendKey function. With this you can send the VK_END. You can find sendkey functions on every delphi site.
Maybe there is another solution (easier), I don't know.

Q2 : I don't get that error?

 if edit1.text = '' then Abort;

 Are you sure you're using the correct syntax?
0
 
LVL 4

Expert Comment

by:itamar
ID: 1346452
Q1) If you increase the points i can give you a piece of code of just ONE line that really works without the use of sendkeys.

Believe me, it works !

Q2)isn't it the old ; missing in the previous line ?? ;)
0
 
LVL 3

Author Comment

by:d4jaj1
ID: 1346453
itamar,

Unfortunately, I only had 20 points when I posted the question, so that's all I could give. Also, I figured it was an easy question, i.e., most experienced Delphi developers would have the answer without needing to think about it or look it up.  I believe I was correct in my assumption since you answer is only one line of code.  The 5 points I added is all I have.  Please help.

Zifnab,

Thanks for your effort, I guess I will use you response if itamar won't help.

0
 
LVL 4

Accepted Solution

by:
itamar earned 20 total points
ID: 1346454
Ok, that is it: (for the challenge - yes i thought about- , not the points)
>>>
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
 if ComboBox1.SelStart = 0 then key := UpperCase(string(key))[1];
end;

You have about 20 questions answered for low points !
I suggest you ask for more to Experts-Exchange or click in the banner to get more points.
(http://www.experts-exchange.com/topics/bin/GenQuiz).
Remember: the default number for Easy questions is 50.
At least give me an A ;) (I hope this helps)
Regards,
0
 
LVL 3

Author Comment

by:d4jaj1
ID: 1346455
Your answer worked perfectly!!  Since you looked at th ereast of my answers, I'm sure you noticed I allways give A's - as long as you answer the question correctly.  Thanks for the 'Gift' and I will remember your efforts the next time I post a question with a significant amount of points.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

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 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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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