home *** CD-ROM | disk | FTP | other *** search
- unit FMain; // Copyright ⌐ 1998 Plasmatech Software Design.
- {
- Shell Control Pack Examples
- NewFileEdit
-
- Creates a new file, makes the new list item visible and starts editing the name.
-
- The MakeNewFile sets things up so the work can be done in the OnInsert event handler.
- }
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, UPTTreeList, UPTShellControls, StdCtrls;
-
- type
- TfrmMain = class(TForm)
- PTShellList1: TPTShellList;
- btnCreate: TButton;
- Memo1: TMemo;
- procedure PTShellList1Insert(Sender: TObject; Item: TListItem);
- procedure btnCreateClick(Sender: TObject);
- private
- FCreatingFile: Boolean;
- FNewFileName: String;
- procedure MakeNewFile;
- public
- { Public declarations }
- end;
-
- var
- frmMain: TfrmMain;
-
- implementation
- uses
- UPTShellUtils;
-
- {$R *.DFM}
- var
- FileNumber: Integer;
-
- {
- This procedure creates the file and sets up state information for the OnInsert event handler.
- }
- procedure TfrmMain.MakeNewFile;
- begin
- try
- PTShellList1.Options := PTShellList1.Options - [ptsloDynamicRefresh];
- {We will handle the refreshing ourselves, so turn off automatic mode for now.}
-
- FCreatingFile := true;
- {This flag is checked in the OnInsert event handler.}
-
- Inc(FileNumber);
- {Give the file a unique number.}
-
- FNewFileName := UPTShellUtils.EnsureTrailingCharDB(PTShellList1.Folder.PathName,'\') +
- 'NewFile'+IntToStr(FileNumber);
- {EnsureTrailingCharDB is a double-byte safe function that makes sure the last character
- in the string is the passed character '\' in this case. Most folders don't end with a '\',
- but root drive folders (c:\) do. Using this function we can get the path name into a
- consistent format to which we can append the file name.}
-
- TFileStream.Create(FNewFileName, fmCreate or fmOpenWrite or fmShareDenyNone).Free;
- {Create the new file stream, free it straight away. This will create an empty file.}
-
- if IsWin95 and (PTShellList1.Folder.IdList = nil) then
- Sleep(2000);
- {Under Windows 95 (and variants) the desktop virtual folder is very slow in registering the
- presence of the new file.}
-
- PTShellList1.RefreshItems;
- {Before this returns, the OnInsert item will be called 1..n times.}
- finally
- FCreatingFile := false;
- PTShellList1.Options := PTShellList1.Options + [ptsloDynamicRefresh];
- end;
- end;
-
- {
- This event handler makes the example work. It checks that the new item is the one we created,
- makes it visible and starts editing.
- }
- procedure TfrmMain.PTShellList1Insert(Sender: TObject; Item: TListItem);
- begin
- if FCreatingFile and
- (AnsiCompareFileName(PTShellList1.GetDataFromItem(Item).PathName, FNewFileName)=0) then
- begin
- Item.MakeVisible(false);
- {Make the item fully visible.}
-
- Item.EditCaption;
-
- FCreatingFile := false;
- {Since we only added one file, we don't need to check any more.}
- end;
- end;
-
- procedure TfrmMain.btnCreateClick(Sender: TObject);
- begin
- MakeNewFile;
- end;
-
- end.
-
-
-