@@ -573,7 +573,7 @@ TWIAManager = class(TObject)
573573 function FindDevice (AName: String; AManufacturer: String=' ' ): Integer; overload;
574574
575575 // Find a Device by it's ID and Select the given Item
576- procedure SelectDeviceItem (ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var AIndex : Integer);
576+ procedure SelectDeviceItem (ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var ADeviceItemIndex : Integer);
577577
578578 property DevMgrIntf: WIA_LH.IWiaDevMgr2 read GetDevMgrIntf;
579579
@@ -1381,22 +1381,23 @@ function TWIADevice.DownloadNativeUI(hwndParent: HWND; useSystemUI: Boolean; APa
13811381 filePaths:= nil ;
13821382 itemArray:= nil ;
13831383
1384- // Maybe pSelectedItem. but does not works
1384+ (*
1385+ // Alternative but this works only with usb connected devices
13851386 lres:= pRootItem.DeviceDlg(dlgFlags, hwndParent,
13861387 StringToOleStr(rDownload_Path), StringToOleStr(rDownload_FileName),
13871388 rDownload_Count, filePaths, itemArray);
1388- (* Alternative
1389- lres:= rOwner.pDevMgr.GetImageDlg(0, StringToOleStr(Self.ID), hwndParent,
1390- StringToOleStr(rDownload_Path), StringToOleStr(rDownload_FileName),
1391- rDownload_Count, filePaths, itemArray);
13921389*)
1390+ lres:= rOwner.pDevMgr.GetImageDlg(dlgFlags, StringToOleStr(Self.ID), hwndParent,
1391+ StringToOleStr(rDownload_Path), StringToOleStr(rDownload_FileName),
1392+ rDownload_Count, filePaths, itemArray);
1393+
13931394 if (lres = S_OK) then
13941395 begin
13951396 // Copy filePaths to DownloadedFiles and Free elements
13961397 SetLength(DownloadedFiles, rDownload_Count);
13971398 for i:=0 to rDownload_Count-1 do
13981399 begin
1399- DownloadedFiles[i]:= filePaths^[i];
1400+ DownloadedFiles[i]:= filePaths^[i]; { #todo 2 -oMaxM : Test if OleStrToString is necessary }
14001401
14011402 if UseRelativePath
14021403 then FullPathToRelativePath(rDownload_Path, DownloadedFiles[i]);
@@ -1408,6 +1409,7 @@ function TWIADevice.DownloadNativeUI(hwndParent: HWND; useSystemUI: Boolean; APa
14081409 end ;
14091410
14101411 if (filePaths <> nil ) then CoTaskMemFree(filePaths);
1412+ // if (itemArray <> nil) then CoTaskMemFree(itemArray); //the documentation says to release it but we always have Exception
14111413 end ;
14121414end ;
14131415
@@ -3198,15 +3200,13 @@ procedure TWIAManager.RefreshDeviceList(PreserveSelected: Boolean);
31983200function TWIAManager.FindDevice (AID: String): Integer;
31993201var
32003202 i :Integer;
3201- curDev :TWIADevice;
32023203
32033204begin
32043205 Result :=-1 ;
32053206 for i:=0 to DevicesCount-1 do
32063207 begin
3207- curDev :=Devices[i];
3208- if (curDev <> nil ) and
3209- (curDev.ID = AID)
3208+ if (rDeviceList[i] <> nil ) and
3209+ (rDeviceList[i].ID = AID)
32103210 then begin Result:=i; break; end ;
32113211 end ;
32123212end ;
@@ -3219,57 +3219,55 @@ function TWIAManager.FindDevice(Value: TWIADevice): Integer;
32193219 Result :=-1 ;
32203220 if (Value <> nil )
32213221 then for i:=0 to DevicesCount-1 do
3222- if (Devices [i] = Value ) then begin Result:=i; break; end ;
3222+ if (rDeviceList [i] = Value ) then begin Result:=i; break; end ;
32233223end ;
32243224
32253225function TWIAManager.FindDevice (AName: String; AManufacturer: String): Integer;
32263226var
32273227 i :Integer;
3228- curDev :TWIADevice;
32293228
32303229begin
32313230 Result :=-1 ;
32323231 for i:=0 to DevicesCount-1 do
32333232 begin
3234- curDev:=Devices[i];
32353233 { #todo -oMaxM : if there is more identical device? }
3236- if (curDev <> nil ) and
3237- (curDev .Name = AName) and
3238- ((AManufacturer <> ' ' ) and (curDev .Manufacturer = AManufacturer))
3234+ if (rDeviceList[i] <> nil ) and
3235+ (rDeviceList[i] .Name = AName) and
3236+ ((AManufacturer <> ' ' ) and (rDeviceList[i] .Manufacturer = AManufacturer))
32393237 then begin Result:=i; break; end ;
32403238 end ;
32413239end ;
32423240
3243- procedure TWIAManager.SelectDeviceItem (ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var AIndex : Integer);
3241+ procedure TWIAManager.SelectDeviceItem (ADeviceID, ADeviceItem: String; var ADevice: TWIADevice; var ADeviceItemIndex : Integer);
32443242var
32453243 i :Integer;
3246- curDev :TWIADevice;
32473244
32483245begin
32493246 ADevice:= nil ;
3250- AIndex := -1 ;
3247+ ADeviceItemIndex := -1 ;
32513248
32523249 try
32533250 for i:=0 to DevicesCount-1 do
32543251 begin
3255- curDev:= Devices[i];
3256-
3257- if (curDev <> nil ) and
3258- (curDev.ID = ADeviceID) then
3252+ if (rDeviceList[i] <> nil ) and
3253+ (rDeviceList[i].ID = ADeviceID) then
32593254 begin
3260- ADevice:= curDev ;
3255+ ADevice:= rDeviceList[i] ;
32613256
3262- if curDev.SelectItem(ADeviceItem)
3263- then AIndex:= ADevice.SelectedItemIndex
3264- else AIndex:= -1 ;
3257+ if ADevice.SelectItem(ADeviceItem)
3258+ then begin
3259+ rSelectedDeviceIndex:= i;
3260+ ADeviceItemIndex:= ADevice.SelectedItemIndex;
3261+ end
3262+ else ADeviceItemIndex:= -1 ;
32653263
32663264 break;
32673265 end ;
32683266 end ;
32693267
32703268 except
32713269 ADevice:= nil ;
3272- AIndex := -1 ;
3270+ ADeviceItemIndex := -1 ;
32733271 end ;
32743272end ;
32753273
0 commit comments