Привет, всем! Я пишу программу для управления файлами мобильной системы Андроид. Мне нужно перевести кусок кода с VB в Delphi. Большую часть кода я перевел сам. Вот что мне надо перевести:
1. Функция "Strip"
Код:
Private Function Strip(psLine As String, psRemoveStr As String) As String
Dim iLoc As Integer
iLoc = InStr(psLine, psRemoveStr)
Do While iLoc > 0
psLine = Left(psLine, iLoc - 1) & _
Mid(psLine, iLoc + Len(psRemoveStr))
iLoc = InStr(psLine, psRemoveStr)
Loop
Strip = psLine
End Function
2. Прцедура "ListDevice"
Код:
Private Sub ListDevice(path As String)
Dim Command As String
Command = ADBPath & " shell busybox ls -1 -A -L -p --color=never " & path
'Update textbox, strip quotes after command
path = Strip(path, Chr(34))
If Right(path, 1) = "/" Then path = Left(path, Len(path) - 1)
If path = "" Then path = "/"
txtDevice.Text = path
'if adb fails then retry
redo:
RunCommand Command
'Start ADB if not running
If Left(ReturnData, 20) = "* daemon not running" Then
AddLog ("ADB server not running")
AddLog "Starting ADB server.."
Shell ("cmd /C " & ADBPath & " start-server")
AddLog "Done"
GoTo redo
End If
lstDeviceDir.Clear
lstDeviceFile.Clear
'lstDeviceDir.AddItem ("..")
'If Not Path = "/" Then lstDeviceDir.AddItem ("/")
Dim myarray() As String
ReDim myarray(1000) As String
myarray() = Split(path, "/")
Dim i As Integer
For i = 0 To UBound(myarray)
If Not myarray(i) = "" Then
lstDeviceDir.AddItem (" | " & myarray(i))
Else
If lstDeviceDir.ListCount = 0 Then lstDeviceDir.AddItem ("/")
End If
Next i
'Catch errors
If ReturnData = "" Then Exit Sub
If Left(ReturnData, Len(ReturnData) - 2) = "error: device not found" Then
MsgBox "Device not found. Please make sure your phone is connected."
lstDeviceDir.Clear
lstDeviceFile.Clear
ADBRemount = False
Exit Sub
End If
'Dim myarray() As String
myarray() = Split(ReturnData, vbCrLf)
'MsgBox ReturnData
'Dim i As Integer
For i = 0 To UBound(myarray)
If (i < UBound(myarray)) Then
myarray(i) = Left(myarray(i), Len(myarray(i)) - 1)
If myarray(i) = "" Then GoTo redo
If Right(myarray(i), 1) = "/" Then lstDeviceDir.AddItem ("" & Left(myarray(i), Len(myarray(i)) - 1))
If Not Right(myarray(i), 1) = "/" Then lstDeviceFile.AddItem (myarray(i))
DoEvents
End If
Next i
End Sub
3. процедура "lstDeviceDir", двойное нажатие
Код:
Private Sub lstDeviceDir_DblClick()
Dim Selection As String
Selection = lstDeviceDir.Text
If Left(Selection, 3) = " | " Then
Dim SkipSection As Boolean
Selection = Right(Selection, Len(Selection) - 3)
Dim myarray() As String
ReDim myarray(1000) As String
myarray() = Split(DevicePath, "/")
DevicePath = ""
Dim i As Integer
For i = 0 To UBound(myarray) - 1
If (i < UBound(myarray)) Then
DevicePath = DevicePath & myarray(i) & "/"
If myarray(i) = Selection Then
i = UBound(myarray) - 1
SkipSection = True
End If
End If
Next i
DevicePath = Chr(34) & DevicePath & Chr(34)
End If
If Selection = ".." Then
If DevicePath = "/" Then Exit Sub
'Dim myarray() As String
ReDim myarray(1000) As String
myarray() = Split(DevicePath, "/")
DevicePath = ""
'Dim i As Integer
For i = 0 To UBound(myarray) - 1
If (i < UBound(myarray)) Then
DevicePath = DevicePath & myarray(i) & "/"
End If
Next i
DevicePath = Chr(34) & DevicePath & Chr(34)
ElseIf Selection = "/" Then
DevicePath = Selection
Else
If SkipSection = False Then
If Not Right(DevicePath, 1) = "/" Then DevicePath = DevicePath & "/"
DevicePath = Chr(34) & DevicePath & Selection & Chr(34)
End If
End If
ListDevice DevicePath
End Sub
Я надеюсь, кто нибудь может помочь мне с переводом. С наступающим всех!