Delphi Caret Position Tedit
Tutorial for using Tedit control. I got two TEdit controls. When I tab out of edit1, edit2 receives the focus. On my OnExit event of Edit1 I have the following code: procedure TForm1.Edit1Exit (Sender: TObject); begin edit2.Enabled:= false; edit2.Enabled:= true; edit2.setfocus; end; Edit2 has the focus. However, there is no caret in it.
I want to get the caret position of my TMemo. What I want is the position of the actual blinking caret, with no regard to if there is any text selected or not. For example if I select a word in a TMemo, the blinking caret can be on the left or right side of the selected word depending on if I selected from right or left.All functions I've found just gives the position of the first char in the selection no matter were the caret is. I've tried TCustomMemo.SelStart, TCustomMemo.CaretPos and the EMGETSEL message but they all give the same response.Any help appreciated, thanks. Anders wrote: Hmm, interesting, I use cbuilder XE2 (Win7 64bit)So do I. I would expect the caret index to be 5 for the left image and 0 for the right one, I highlighted the caret with an arrow. Are you saying you get a different result on your machine?With your code, I am getting the same result as you (using the keyboard tohighlight text in either direction).
When the caret is at the front of theselection, the resulting index is the value of the end of the selection,presumably because that is the 'start' of the selection. When the caretis at the end of the selection, the resulting index follows the caret asexpected.In my earlier test, I was invoking the CaretPos calculation in a TButtonOnClick event instead, and the resulting index followed the actual caretas expected, regardless of selection. But when I try it again, it is notfollowing anymore.-Remy Lebeau (TeamB). Mark Jacobs wrote: wrote in message news:497658@forums.embarcadero.com. I have this nice code hack to work around that, charPos will not overflow just wrap around. I didn't add it to my first code as it wasn't part of the original problem.
Tricky stuff. Which only goes to prove, 'Where there's a will, there's a way!' Regards,Where there's a Will, there's a Wheaton.-Rudy Velthuis'The rights of women are sacred. See that women are maintainedin the rights attributed to them.' - Prophet Muhammed.
Delphi Caret Position Tedit For Mac
QuoteIs it possible to get the Caret Position in a TEdit or TMemo in ScreenCoordinates?Use Windows.GetCaretPos and convert the returned coordinates from client toscreen coordinates using the edits/memos ClientToScreen method.You can also send a EMPOSFROMCHAR message to the control with the SelStartvalue as character position. Beware of differences in parameter usage betweenedits and richedits for this message!Peter Below (TeamB)Use the newsgroup archives:. 1.
Delphi Tedit Caret Position
2. 3. 4.
Delphi Tedit Get Caret Position
5. 1. 2. 3. 4.
5.
Delphi Cursor Position In Tedit
Welcome to the Delphi Tips micro-site.
There are over 200 Delphi Tips here. Choose them from the list below.
- A general purpose Base64 decoding routine using Indy (#157)
- Add animation effects to your forms (#188)
- Adding component help to Delphi (#40)
- Animate tray application windows as they open and close (#48)
- Animate windows as they are opened and closed (#46)
- Auto-resizing and centring forms on screen (#67)
- BDE API Overview (#212)
- Boyer-Moore-Horspool text searching (#41)
- Calling CreateProcess() the easy way (#4)
- Change the button captions in a message dialog box (#173)
- Change the Delphi Object Inspector font size (#224)
- Change the font used in hints (#199)
- Check if an HTML element is displayed (#69)
- Check if computer is connected to the internet (#223)
- Check that a HTML document has completely loaded (#72)
- Communicate between processes using windows messaging (#51)
- Communicate with Windows Program Manager using DDE (#137)
- Convert between long and short file names (#6)
- Convert strings to character sets and vice versa (#234)
- Delete files with the ability to undo or recycle (#10)
- Delete or clear rows in a TStringGrid (#191)
- Detect if an application has stopped responding (#124)
- Different ways of executing applications and files from Delphi (#134)
- Dim the main application form when a dialog box is displayed (#228)
- Display the Browse for Folder dialog box (#63)
- Display the Windows Disconnect Network Drive dialog box (#175)
- Double quote a string that has spaces (#225)
- Draw a DBGrid with alternating row colours (#182)
- Drawing disabled text (#54)
- Drawing outlined text (#55)
- Drawing rotated text (#22)
- Encrypt and decrypt functions (#73)
- Ensure a form stays in the background (#189)
- Execute a DOS command and capture the output (#61)
- Execute a program and wait until it is done (#17)
- Extract keywords from an HTML document (#68)
- Fast string file searching (#42)
- File Open/Save Common Dialog Control IDs (#70)
- Find the position of the text cursor in a memo control (#125)
- Find the taskbar and system tray window handles (#47)
- Finding HTML elements by ID in a TWebBrowser document (#56)
- Force a TEdit to accept only numeric input (#151)
- Force display of a ToolButton's PopupMenu when the button is clicked (#197)
- Get the network computer and domain names (#62)
- Getting and setting the user and system environment variables (#64)
- How can I add my own custom menu item to another application? (#38)
- How to access the Registry using Windows API (#14)
- How to add a context menu item to Windows Explorer (#15)
- How to add an OnMouseDown event to a TPopupMenu (#117)
- How to add text completion capability to a TComboBox (#110)
- How to adjust RGB values using TTrackBars (#142)
- How to blend two pf24bit images using ScanLine (#147)
- How to block input to the system until released (#44)
- How to block pasting of text from the clipboard into an enabled TEdit (#207)
- How to calculate intersection points of lines or line sections with rectangles (#220)
- How to calculate the area of a polygon (#221)
- How to calculate the minimum distance between two polygons (#218)
- How to call CopyFileEx and let the callback update a progress bar (#160)
- How to call Internet Explorer from Delphi (#2)
- How to centre text in a TEdit (#85)
- How to centre text in a TEdit (alternative approach) (#159)
- How to change the corner size of RoundRect (#149)
- How to change the drag cursor image when dragging in a TTreeView (#119)
- How to check if a key is pressed (#45)
- How to check if a program is installed using its program identifier (#233)
- How to check if a string is a number (#27)
- How to check if a TTreeView is fully expanded or collapsed (#90)
- How to check if the BDE is installed (#28)
- How to compare two pf24bit images (#145)
- How to control the scroll buffer of a TMemo (#102)
- How to convert a *.bmp file to a *.jpg file (#97)
- How to convert an integer value to a Roman Numeral representation (#101)
- How to convert Delphi forms from binary to text and vice versa (#66)
- How to convert hex colour values into Delphi formatted ones (#140)
- How to convert TDateTime to a UNIX timestamp and vice versa (#30)
- How to copy data between TWebBrowsers (#13)
- How to copy multiple files into one (#165)
- How to create a borderless TComboBox (#84)
- How to create a brush using CreateBrushIndirect (#98)
- How to create a greyscale palette (#215)
- How to create a GUID (#214)
- How to create a non-rectangular TPanel (#94)
- How to create a pie chart (#148)
- How to create a resizable TPanel with a size grip (#92)
- How to create a TCheckBox with a transparent caption (#82)
- How to create a TComboBox with incremental search capabilities (#83)
- How to create a TDrawGrid where all cells act as buttons (#206)
- How to create a TEdit that accepts only numeric input (#86)
- How to create a TGroupBox with a checkbox that disables / enables all contained controls when checked (#112)
- How to create a TListBox that is resizable at runtime (#114)
- How to create a TListBox with Drag and Drop capabilities (#115)
- How to create a TMemo with alternating colours to paint the lines (#87)
- How to create a transparent TMemo (#209)
- How to create a transparent TPanel (#210)
- How to create a TScrollBar with a background bitmap (#120)
- How to create a TScrollBox with its own background (#121)
- How to create a TTreeView with a three state checkbox (#118)
- How to create a TTreeView without scrollbars (#91)
- How to create a virtual drive (#229)
- How to create components with a transparent background (#74)
- How to createLasso' (#146)
- How to implement a custom component paint method that is dependent on outside data (#195)
- How to implement a multi-line caption on a TButton (#81)
- How to implement an OnAfterExecute event in a TActionList (#205)
- How to implement an OnMouseDown event for the buttons of a TRadioGroup (#122)
- How to implement autocompletion in a TEdit (#111)
- How to implement drag and drop at design time (#76)
- How to know if the mouse has entered the component area (#35)
- How to make a child form listen to broadcasted messages (#89)
- How to make a single instance of your application (#178)
- How to make a TCollectionItem contain a TCollection (#109)
- How to minimize the controls in a form (#174)
- How to mix or separate three color channels (#141)
- How to paint a translucent (not transparent) rectangle (#203)
- How to paint on a TControlCanvas in a TMemo (#208)
- How to paste files from Windows Explorer into your application (#161)
- How to perform a Shell Sort (#12)
- How to prevent a TListView from displaying tool tips for long items (#158)
- How to prevent a TWebBrowser from displaying a document's background (#58)
- How to print text and text files in Delphi (#32)
- How to programmatically make your programs run on Windows startup (#7)
- How to read bitmap file information (#19)
- How to read image pixels fast (#21)
- How to read the installed ADO version (#29)
- How to read Unicode text files (#168)
- How to read very large text files fast (#169)
- How to reduce the number of Set methods in a component (#108)
- How to refresh file icons (#18)
- How to register a global hotkey (#16)
- How to replace text in a Word document (#136)
- How to resize a *.jpg image and save the result to a file (#99)
- How to resize a TPanel at runtime (#93)
- How to resolve a host name (#25)
- How to retrieve all available TBrushStyle values as a list of strings (#222)
- How to retrieve rich text from a resource file and save it to disk (#153)
- How to retrieve the CPU vendor ID (#231)
- How to rotate a 2D point (#219)
- How to save 32 bit bitmaps in 24 bit bmp format (#202)
- How to save and load a TStringGrid to and from a file (#177)
- How to save and load printer settings to / from the registry (#104)
- How to save and restore font selections to a text file (#163)
- How to save several TBitmaps into one file (#100)
- How to save the canvas of a TPaintBox to a .bmp file (#152)
- How to save the font settings of a control to the registry (#192)
- How to search for a pattern in a file (#155)
- How to send a message to a specific control on a TForm (#105)
- How to send a simulated key press to the active control (#170)
- How to set boundaries for newly created controls (#77)
- How to snap a window to the screen edge (#36)
- How to subclass the default Delphi Dock Manager (#193)
- How to swap two integers without using a temporary variable (#180)
- How to tell Netscape Navigator which web pages to load from your Delphi program (#3)
- How to trap the ALT key state in a visual component (#80)
- How to turn numlock on by code (#26)
- How to use a function or a procedure as a parameter to another function (#129)
- How to use a scroll event in a TListBox (#113)
- How to use a TControlCanvas in a component (#75)
- How to use the alpha transparency features included in Windows 2000 and later (#96)
- How to wipe a file (#184)
- How to write a custom TAction to control the visibility of a TStatusBar (#204)
- How to write a list of strings to the registry (#88)
- Implementing a custom loop (#226)
- Incremental search of list box (#39)
- Inserting RTF code into a rich edit control (#57)
- Install components and IDE extensions into the Delphi IDE (#106)
- List of BDE error codes (#211)
- Making LMD buttons work when clicked (#65)
- Merging files (#60)
- Message box that works with a Delphi Service Application (#49)
- Move the mouse cursor from code (#1)
- Open documents and URLs in their associated applications (#5)
- Optimised replacements for DecodeDate and EncodeDate (#230)
- Prevent a Delphi form from being moved (#187)
- Prevent a Delphi form from being moved off screen (#183)
- Prevent flicker on graphics controls (#43)
- Prevent system sleep (#127)
- Print any type of document using Delphi (#131)
- Programatically log users off (#135)
- Reading and writing INI files (#59)
- Remove recently opened projects from the CodeGear RAD Studio IDE welcome page (#107)
- Right align main menu items (#128)
- Scanning MS Office documents using the MS Anti-virus API (#126)
- Search for help (#8)
- Serialize application settings (#133)
- Simulate the Visual Basic SendKeys and AppActivate routines in Delphi (#181)
- Solution for problem with auto update feature in Rad Studio 2010 and Win Vista/7 UAC (#156)
- Sort TStrings objects with extra functionality ala UNIX style parameters (#172)
- Take a screen shot of an inactive window (#186)
- Terminate a process instantly (#190)
- The purpose and use of DispInterface (#217)
- Triggering default menu items from code (#53)
- Using the TStrings.ValueFromIndex property (#130)
- What is a DispInterface? (#216)
- When was that file last accessed? (#9)
- Which COM objects to use? (#132)
The tips were taken from the old version of the DelphiDabbler website. The new version of the site does not host the tips and links here.
Be warned that these tips are now quite old, few have ever been tested and those that have were tested on an old version of Delphi.
These tips are also available in PDF format and as an SQL database from the Delphi Tips GitHub Repository. Additional tips will also be found there in the extra
folder.
Any bugs in this site can be reported on the project's issues page. (GitHub account required).
Corrections of any errors in the tips are welcome: use the same issues page to submit them. If you notice an error but don't provide a fix the tip will simply have a note about the error attached to it – it will not be fixed!