Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use my own Inplace-Editors in Grids Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
21-Jul-03
Category
VCL-General
Language
Delphi 2.x
Views
93
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Alex Schlecht

String-Grids are very usefull, but sometimes it's necessary to use an own 
Inplace-Editor. For example to make a Grid which will allow only numbers but no 
Text-Characters. 

Answer:

When you are using Grids (TStringGrid, TDBGrid), you can input some text in the 
cells of the grid. This will be done with the "Inplace-Editor" from Borland. 

Sometimes it's necessary to make an own Inplace-Editor, for example to prevent the 
user to give in Text instead of number. The following example shows how to do this. 

First you need two new classes: one for your Grid and one for your Inplace-Editor. 
In this example I use TStringGrid, but it should also work with TDBStringGrid. 

1   unit u_TMyStringGrid;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     Grids;
8   
9   type
10  
11    // My own Inplace-Editor. This Editor -for example- only
12    // allow numbers, no text
13    TMyInplaceEdit = class(TInplaceEdit)
14    protected
15      procedure KeyPress(var Key: Char); override;
16    end;
17  
18    // My own StringGrid, which will use my own Inplace-Editor
19    TMyStringGrid = class(TStringGrid)
20    protected
21      function CreateEditor: TInplaceEdit; override;
22    end;
23  
24  implementation
25  
26  { TMyStringGrid }
27  // Here i define, that my StringGrid should use MyInplace-Editor
28  
29  function TMyStringGrid.CreateEditor: TInplaceEdit;
30  begin
31    Result := TMyInplaceEdit.Create(Self);
32  end;
33  
34  { TMyInplaceEdit }
35  //The Inplace-Edit only allowes numers, no text-Characters
36  
37  procedure TMyInplaceEdit.KeyPress(var Key: Char);
38  begin
39    if not (Key in ['0'..'9']) then
40    begin
41      beep;
42      Key := #0
43    end
44    else
45      inherited;
46  end;
47  
48  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC