procedure TForm1.CreateDirectory1Click(Sender: TObject);<br>var<br> ErrorMessage: Pointer; // holds a system error message<br> ErrorCode: DWORD; // holds a system error code<br>begin<br> {determine if a directory path has been specified}<br> if DirName.GetTextLen = 0 then<br> begin<br> StatusBar1.SimpleText := 'Directory name not specified';<br> Exit;<br> end;<br><br><br> {if so, then create the new directory under the current directory}<br> if not CreateDirectory(PChar(DirectoryListBox1.Directory + '/' +<br> DirName.Text), nil) then<br> begin<br> {if there was an error creating the directory, display the error message}<br> ErrorCode := GetLastError;<br> FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM,<br> nil, ErrorCode, 0, @ErrorMessage, 0, nil);<br><br> StatusBar1.SimpleText:='Error Copying File: '+string(PChar(ErrorMessage));<br> LocalFree(hlocal(ErrorMessage));<br> end;<br><br> {update the directory listing to show the new directory}<br> DirectoryListBox1.Update;<br>end;<br><br>procedure TForm1.CreateDirectoryFromTemplate1Click(Sender: TObject);<br>var<br> ErrorMessage: Pointer; // holds a system error message<br> ErrorCode: DWORD; // holds a system error code<br><br>begin<br> {determine if a directory path has been specified}<br> if DirName.GetTextLen = 0 then<br> begin<br> StatusBar1.SimpleText := 'Directory name not specified';<br> Exit;<br> end;<br><br> {if so, then create the new directory under the current directory}<br> if not CreateDirectoryEx(PChar(Template.Text),PChar(DirectoryListBox1.<br> Directory + '/' + DirName.Text), nil) then<br><br> begin<br> {if there was an error creating the directory, display the error message}<br> ErrorCode := GetLastError;<br> FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM,<br> nil, ErrorCode, 0, @ErrorMessage, 0, nil);<br> StatusBar1.SimpleText:='Error Copying File: '+string(PChar(ErrorMessage));<br> LocalFree(hlocal(ErrorMessage));<br> end;<br><br> {reset UI elements}<br> Template.Text := '';<br><br> CreateDirectoryFromTemplate1.Enabled := FALSE;<br> CreateDirectory1.Enabled := TRUE;<br> Template1.Enabled := TRUE;<br> ClearTemplate1.Enabled := FALSE;<br><br> {update the directory listing to show the new directory}<br> DirectoryListBox1.Update;<br>end;<br>