Short File Name from Long File Name. Hi, I need to get my App. I can shell call an old 1. Anyone have a function which would 'mangle' the LFN's to SFN's? C: \Program Files' - -> 'C: \progra~1') TIA for any help. Regards, Dale. Dale Brownbridge Senior Software Developer Image Software Pty Ltd (Melbourne, Australia) Email : d..@isoftware. Phone : +6. 1 (0)3 9. Mobile: +6. 1 (0)4. Convert between long and short file names. Navigation. Home Page; Programs; Delphi Library; Snippets & Tips. Now a function to convert a short file name into. Board index » delphi » Short File NAmes. [email protected] (HOBBES) Delphi Developer. Get a short file name from a long file name (including SFN path). Any answers?
DELPHI Tips & Tricks. This page is still General. Avoid concatenation of strings, because it's rather slow! This is how you should *NOT* implement string functions. Result : = Result + ch. Replace. Char. Slow (const s: string. Result : = ''''. for i : = 1 to length (s) do. Result : = Result + ch. Result : = Result + s [i]. You can avoid string concatenation as well as the. Replace. Char. Fast (const s: string. Result : = s. for i : = 1 to length (Result) do. Result [i] = ch. 1 then. Result [i] : = ch. The Sys. Utils function Ansi. Upper. Case is rather slow. Windows API call (Char. Upper. Buff). To speed- up this, simply use an array initially. ANSI upper characters and write. Convert. To. ANSIUpper (it is about. ANSIUpper: array [char] of char. ANSI upper characters because. ANSIUppercase is very slow. Fill. ANSIUpper. for ch : = Low (char) to High (char) do. ANSIUpper [ch] : = Ansi. Upper. Case (ch) [1]. ANSI uppercase. about 3. ANSIUppercase function. Convert. To. ANSIUpper (const s: string): string. Result : = s. for i : = 1 to length (Result) do. Result [i] : = ANSIUpper [Result [i]]. Fill. ANSIUpper. Files. Get the short file name (8 + 3) from a Win. Short. File. Name (const File. Name: string): string. Tmp: array[0. 2. 55] of char. File. Exists (File. Name) then. Result : = ''. Get. Short. Path. Name (PChar (File. Name), a. Tmp, Sizeof (a. Tmp) - 1) = 0. Result: = File. Name. Result: = Str. Pas (a. Tmp). Get the long file name from a shortened (8 + 3) file name. Long. File. Name (Short. Name: string): string. SR: TSearch. Rec. Result : = ''. if (pos ('\\', Short. Name) + pos ('*', Short. Name) +. pos ('?', Short. Name) < > 0) or not File. Exists (Short. Name). Net. BIOS name, joker chars and invalid file names }. Find. First (Short. Name, fa. Any. File, SR) = 0 do begin. Result : = '\' + SR. Name + Result. Sys. Utils. Find. Close (SR); { the Sys. Utils, not the Win. Procs procedure! }. Short. Name : = Extract. File. Dir (Short. Name). if length (Short. Name) < = 2 then. Break; { Short. Name contains drive letter followed by ': ' }. Result : = Extract. File. Drive (Short. Name) + Result. Create all directories needed for a new path at once. Suppose you want to create a new path C: \APPS\SALES\LOCAL, but the directory C: \APPS. Using the procedure Force. Directories in unit File. Ctrl, you can. create the whole path at once. Dir : = 'C: \APPS\SALES\LOCAL'. Force. Directories(Dir). Directory. Exists(Dir) then. Label. 1. Caption : = Dir + ' successfully created.'. Dialog for selecting directory. Use the function Select. Directory in unit File. Ctrl. Look in the online help for more information. Dir : = 'C: \Windows'. Select. Directory(Dir, [sd. Allow. Create, sd. Perform. Create, sd. Prompt], 0) then. Label. 1. Caption : = Dir. Help Files. Display the help contents in 3. Place in the On. Click event of the menu item the following code: Application. Help. Command (HELP_FINDER, 0); Implement your own "What's this" button Place in the On. Click event of the button the following code: Post. Message (Handle, WM_SYSCOMMAND, SC_CONTEXTHELP, 0); IDEKeystroke recording and playing back. Press [Ctrl][Shift][R] to start recording. Type in the keystrokes you want to play back. Press [Ctrl][Shift][R] to stop recording. Press [Ctrl][Shift][P] to play back. Note: This only works with default keymapping. To find out what keymapping you are using. Environment | Options in the Tools menu. In the Editor Tab, you will see. Editor Speedsetting Combobox. Code markers. Press [CTRL][K], followed by a number from 0 to 9 to set a position. Press [CTRL][Q], followed by a number from 0 to 9 to go to a saved position. Mark a rectangular block. First method. Press and hold down [ALT][SHIFT]. Press the left, right, up or down arrow keys to mark a rectangle. Press and hold down [ALT]. What does the blue dots at the left mean? After compiling a project, a small blue dot in the left hand gutter is indicating a "living" line. Otherwise, the line is "dead", i. This feature is not available in DELPHI 1/2. Problems with debugger caused by wrong terminated lines. During debugging a unit containing dozens of utility procedures and. I recently noticed a strange effect. When tracing into the. This happened using both DELPHI 2 and 4. When I activated. CPU window, I additionally noticed some comment lines in the. Finally using a hex editor, it turned out that there were exactly. A instead of $0. D$0. A (CR/LF). Reason. I downloaded a file containing C code from the web and pasted some. Obviously, it was a UNIX file. Download project demonstrating this effect (3 KB). Download application to convert UNIX files to Windows format (executable only, 1. KB). Download source code for application to convert UNIX files to Windows format (4 KB). Setting the default project directory. Right click on the Windows shortcut icon used to start Delphi. Select properties from the menu. C: \My. Projects). Unfortunately, this doesn't work. Windows 9. 8. Workaround for Windows 9. Start Delphi and create a new project. Use File | Save Project As.. C: \My. Projects\Unit. C: \My. Projects\Project. Make sure that both files are saved within this directory (Win. My Directorytwice). Right click on the Windows shortcut icon used to start Delphi. Select properties from the menu, and append. The target should now read as e. C: \Program Files\Borland\Delphi. Bin\delphi. 32. exe" C: \My. Projects\Project. OOPAccess protected class properties. Declare a class inherited from the class you want to access: type. TExposed. Win. Control = class (TWin. Control). Type- cast the object: if Sender is TWin. Control then. TExposed. Win. Control(Sender). Caption : = 'New Caption'. Using TList. The TList class is used to hold (pointers to) objects inherited from. TObject. The number of those objects can be defined at runtime. In our example, we declare in step 1 a class for the items you want to add to the list. Our items consist of a. TList instance }. TMy. List. Item = class (TObject). Suppose, on Form. List. Box. 1, Spin. Edit. 1, and Button. Spin. Edit. 1 determines the number of TMy. List. Item items added to the list when. Button. 1 is clicked. Then, the list is filled with items which are displayed. List. Box. 1. Implement the following On. Click event for Button. TForm. 1. Button. Click(Sender: TObject). List: TList. j: integer. List }. List : = TList. Create. for j : = 1 to Spin. Edit. 1. Value do begin. List. Add (TMy. List. Item. Create). with TMy. List. Item (List. Items [j - 1]) do begin. Int. To. Str (j). List. Box. 1. Items. Clear. for j : = 0 to List. Count - 1 do. List. Box. 1. Items. Add (TMy. List. Item (List. Items [j]). s + ', i = ' +. Int. To. Str (TMy. List. Item (List. Items [j]). i)). { free each item, see note 2 below }. List. Count - 1 do. TMy. List. Item (List. Items [j]). Free. No variables are declared to hold TMy. List. Item instances, because the number. Because TList is not aware of the items' class type, the Free method of. TList can't remove the objects from memory. We have to free each. VCLProvide a horizontal scrollbar for a list box. Listbox with horizontal scrollbar. Max. Width < 0 : adapt automatically to largest item. Max. Width > = 0: use value of Max. Width for width of scrollable area. Hor. Scroll. Bar (List. Box: TList. Box; Max. Width: integer). var i, w: integer. Max. Width > = 0 then. Send. Message(List. Box. Handle, LB_SETHORIZONTALEXTENT, Max. Width, 0). { get largest item }. List. Box. Items. Count - 1 do with List. Box do begin. w : = Canvas. Text. Width (Items [i]). Max. Width then. Max. Width : = w. Send. Message(List. Box. Handle, LB_SETHORIZONTALEXTENT. Max. Width + Get. System. Metrics (SM_CXFRAME), 0). Center a form on screen at runtime. Center. Form (AForm: TForm). ALeft, ATop: integer. ALeft : = (Screen. Width - AForm. Width) div 2. ATop : = (Screen. Height - AForm. Height) div 2. AForm. Set. Bounds (ALeft, ATop, AForm. Width, AForm. Height). Center a form over active form at runtime. Center. Form. Over. Active (AForm: TForm). ALeft, ATop: integer. ALeft : = Screen. Active. Form. Left +. Screen. Active. Form. Width div 2) - (AForm. Width div 2). ATop : = Screen. Active. Form. Top +. Screen. Active. Form. Height div 2) - (AForm. Height div 2). { prevent form from being outside screen }. ALeft < 0 then. ALeft : = Screen. Active. Form. Left. ATop < 0 then. ATop : = Screen. Active. Form. Top. if (ALeft + AForm. Width > Screen. Width) or. (ATop + AForm. Height > Screen. Height). Center. Form (AForm). AForm. Set. Bounds (ALeft, ATop, AForm. Width, AForm. Height). Prevent labels from being cut. When switching between small fonts and large fonts, the Auto. Size property of TLabel components. As work- around, call the following procedure within the form's On. Create. procedure Labels. Auto. Size. Correct (Form: TForm). Component: TComponent. Form. Component. Count - 1 do begin. Component : = Form. Components [i]. if (Component is TLabel) and TLabel (Component). Auto. Size then begin. TLabel (Component). Auto. Size : = false. TLabel (Component). Auto. Size : = true. Determine if mouse cursor is over a component at runtime. Control? ***********************************************************************}. Is. Mouse. Over (Control: TControl): boolean. Get. Cursor. Pos (p) then begin. Control. Screen. To. Client (p). { coordinates within Control? Result : = (p. x > = 0) and (p. Control. Width) and. Control. Height). Result : = false. Win. 32 APIUsing Enum. Windows. The following example lists the captions of all visible windows in a listbox. Window. List: TList. Enum. Child. Windows called for each window. Get. Window (Handle: HWND; LParam: longint): bool; stdcall. Result : = true. { add each handle to the list }. Window. List. Add (Pointer(Handle)). TForm. 1. Button. Click(Sender: TObject). Buffer: array [0. Window. List : = TList. Create. { get all windows }. Enum. Windows (@Get. Window, 0). List. Box. 1. Items. Clear. Window. List. Count - 1 do begin. Hnd : = HWND (Window. List [i]). if Is. Window. Visible (Hnd) then begin. Get. Window. Text (Hnd, Buffer, Size. Of (Buffer) - 1). Buffer [0] < > #0 then. List. Box. 1. Items. Add (Str. Pas (Buffer)). Window. List. Free.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
August 2016
Categories |