OSDN Git Service

少し変更
authoryamat0jp <terukohietori@gmail.com>
Sun, 26 Apr 2020 02:27:10 +0000 (11:27 +0900)
committeryamat0jp <terukohietori@gmail.com>
Sun, 26 Apr 2020 02:27:10 +0000 (11:27 +0900)
Unit1.pas

index 6aadf7f..9c0bad7 100644 (file)
--- a/Unit1.pas
+++ b/Unit1.pas
@@ -56,7 +56,7 @@ procedure TForm1.ListBox1Click(Sender: TObject);
 var
   path, filename: string;
   filelist: TStringDynArray;
-  Win32Result: integer;
+  lResult: Cardinal;
   NR: TNetResource;
   password, user: PChar;
 begin
@@ -72,13 +72,15 @@ begin
   end;
   password := PChar('');
   user := PChar('');
-  if WNetAddConnection2(NR, password, user, 0) = NO_ERROR then
+  lResult := WNetAddConnection2(NR, password, user, 0);
+  if lResult in [NO_ERROR, ERROR_ALREADY_ASSIGNED] then
   begin
     path := ExcludeTrailingPathDelimiter(NR.lpRemoteName);
     NR.lpRemoteName := PChar(path);
     filelist := TDirectory.GetFiles(path, '*.mp3',
       TSearchOption.soAllDirectories);
-    WNetCancelConnection2(NR.lpRemoteName, 0, False);
+    if lResult = NO_ERROR then
+      WNetCancelConnection2(NR.lpRemoteName, 0, False);
   end;
   for filename in filelist do
     ListView1.Items.Add.Text := filename;