?
Solved

Delphi 2005 - how do i get edit events apart from default click ? what must i import for uppercase and trim to work

Posted on 2005-04-14
18
Medium Priority
?
169 Views
Last Modified: 2010-04-05
hi,
i have a edit, when i click on it i get the click event, but i want the keypress event , how can i get that?
in vb all i did was select the control and the event in the top right dropdownlist, but i cant do that in delphi.

i use uppercase and trim , but neither want to work so i need to insert a use system.something at the top.


thanks!!
0
Comment
Question by:jxharding
  • 9
  • 5
  • 4
18 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13779951
The is a standrard keypress event that is available for TEdit components
Select your editbox, open your object inspector and choose the "Events" tab.
You should see an OnKeyPress event listed there.
Double click the event to start coding for it.

What are you trying to use Uppercase and Trim for so I can answer.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13779958
Uppercase and Trim are in the "SysUtils" unit
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13779961
F11 opens your object inspector btw
0
Independent Software Vendors: 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!

 

Author Comment

by:jxharding
ID: 13779999
thanks , i saw the events tab , but nothing happened when i double clicked on it,
im reinstalling delphi now, its really slow , even slower than the Visual Studio IDE.

im sure i tried using System.Sysutils last night, but nothing worked
the help is also really crap , with absolutely no examples as far as i've seen.

(sorry got to get that out)

so i add, system.sysutils
to the use statement?
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13780047
You dont need to double click the events tab, just select it like you would a tab control and there should be a list of about 18 different default events for the edit box.
It shows 2 columns of information under the events tab, 1 for the event name and then a blank box to the right of the name. Double click in the right hand side to automatically start the base coding into your application

I dont think you need the system. part unless delphi 2005 has changed from the version delphi 7 I am using.
Just add SysUtils.

If you type either Trim or Uppercase somewhere in code, then place your cursor over the word and press F1, it should open the help on it and list the unit that the declaration is located in. This should work for all delphi commands.
0
 

Author Comment

by:jxharding
ID: 13780105
hi ,there is a definitive difference here.
when i click on the object explorer i see the events but nothing happens when i double click it.

also here is the code, i tried looking at the help file :
UpperCase Routine
 
Returns a copy of a string in uppercase.
 
Namespace
Borland.Vcl.SysUtils

Syntax
[Delphi] function UpperCase(const S: string): string;
[Delphi] function UpperCase(const S: string, LocaleOptions: TLocaleOptions): string;
Description
UpperCase returns a copy of the string S, with the same text but with all 7-bit ASCII characters between 'a' and 'z' converted to uppercase. To convert 8-bit international characters, use AnsiUpperCase instead.
 



the code:
unit Assignment2Q2;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data, System.SysUtils;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    btnGenerate: System.Windows.Forms.Button;
    edtInput: System.Windows.Forms.TextBox;
    gpbAbbrev: System.Windows.Forms.GroupBox;
    lblAbbrev: System.Windows.Forms.Label;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure btnGenerate_Click(sender: System.Object; e: System.EventArgs);
    procedure edtInput_TextChanged(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

{$AUTOBOX ON}

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
begin
  Self.btnGenerate := System.Windows.Forms.Button.Create;
  Self.edtInput := System.Windows.Forms.TextBox.Create;
  Self.gpbAbbrev := System.Windows.Forms.GroupBox.Create;
  Self.lblAbbrev := System.Windows.Forms.Label.Create;
  Self.gpbAbbrev.SuspendLayout;
  Self.SuspendLayout;
  //
  // btnGenerate
  //
  Self.btnGenerate.Location := System.Drawing.Point.Create(72, 160);
  Self.btnGenerate.Name := 'btnGenerate';
  Self.btnGenerate.TabIndex := 0;
  Self.btnGenerate.Text := 'Generate';
  Include(Self.btnGenerate.Click, Self.btnGenerate_Click);
  //
  // edtInput
  //
  Self.edtInput.Location := System.Drawing.Point.Create(16, 112);
  Self.edtInput.Name := 'edtInput';
  Self.edtInput.Size := System.Drawing.Size.Create(184, 20);
  Self.edtInput.TabIndex := 1;
  Self.edtInput.Text := '';
  Include(Self.edtInput.TextChanged, Self.edtInput_TextChanged);
  //
  // gpbAbbrev
  //
  Self.gpbAbbrev.Controls.Add(Self.lblAbbrev);
  Self.gpbAbbrev.Location := System.Drawing.Point.Create(224, 64);
  Self.gpbAbbrev.Name := 'gpbAbbrev';
  Self.gpbAbbrev.Size := System.Drawing.Size.Create(200, 104);
  Self.gpbAbbrev.TabIndex := 2;
  Self.gpbAbbrev.TabStop := False;
  Self.gpbAbbrev.Text := 'The Abbreviation';
  //
  // lblAbbrev
  //
  Self.lblAbbrev.Location := System.Drawing.Point.Create(8, 40);
  Self.lblAbbrev.Name := 'lblAbbrev';
  Self.lblAbbrev.Size := System.Drawing.Size.Create(184, 23);
  Self.lblAbbrev.TabIndex := 0;
  //
  // TWinForm
  //
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(440, 273);
  Self.Controls.Add(Self.gpbAbbrev);
  Self.Controls.Add(Self.edtInput);
  Self.Controls.Add(Self.btnGenerate);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Self.gpbAbbrev.ResumeLayout(False);
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm.edtInput_TextChanged(sender: System.Object; e: System.EventArgs);
begin
  lblAbbrev.text := '';
end;

procedure TWinForm.btnGenerate_Click(sender: System.Object; e: System.EventArgs);
var
  InString : string;
  Position : integer;

begin
 //lblAbbrev.Text := lblAbbrev.text + UpperCase(edtInput.Text[1]) + '.'
    InString := Trim(edtInput.text);
    if InString = '' then
      exit;
    lblAbbrev.text := lblAbbrev.text + Uppercase(copy(instring,1,1)) + '.';

    Position := Pos(' ', InString);

    if Position > 0 then
      begin
        Delete(instring,1,Position);
        edtInput.text := InString;
      end
    else
        edtInput.text := '';
end;


end.




i still cant get the trim and uppercase to work , neither the uppercase

0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13780154
Ok I dont see what the issue is unfortunately as I dont use Delphi 2005 yet Im afraid. I cant even have a look at the help to see if I can find the uppercase and trim functions for you. They must be in a commonly used unit as they are so widely used.

Sorry I cant be of more help  :o/
0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 2000 total points
ID: 13780909
Ok just found out this bit of information regarding Trim and Uppercase

Trim and Upper case now are part of String class, so you could just call them as:

    YourString := Edit1.text.Trim();
    if YourString = '' then
      exit;
    Label1.text := Label1.text + (copy(YourString.ToUpper(),1,1)) + '.'
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13780923
Got that information from mnasman btw
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 13780926
Hello

  You are working with winforms, so the units that you had workd with delphi will not work, but most of the functionality available in the dot net

for example Trim and Upper case now are part of String class, so you could just call them as:


    InString := edtInput.text.Trim();
    if InString = '' then
      exit;
    lblAbbrev.text := lblAbbrev.text + (copy(instring.ToUpper(),1,1)) + '.';

HTH

Regards,
Mohammed
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 13780948
LOL, I put the answer in another question 30 min ago, I just recognized that I put in wrong question,but mikelittlewood, was faster than me to know that ;-)
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13781124
Sorry mnasman, I didnt read the other question you had put it in but assumed he was asking a similar question, so I let this person know as well.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 13781163
don't worry mikelittlewood ;-)
0
 

Author Comment

by:jxharding
ID: 13781792
thank you
any news on the event?
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 13781845
what problem do you have with the Event?
mikelittlewood answer valid for delphi 2005, I just tested it now, just double click on OnKeyPress event from Object inspector
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 13803914
I shoul be careful next time :-(
0
 

Author Comment

by:jxharding
ID: 13803954
thank you both for the the help.
the text part was spot on.
the even part was right, i just had to double click on the right section (as opposed to the left) on the event.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13804466
Glad we could help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 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