关于读写磁带机的问题(100分)

L

LanHer

Unregistered / Unconfirmed
GUEST, unregistred user!
我要写一个备份程序,但是不知道如何读写磁带机,请高手帮忙!
 
没接触过,帮你UP一下
 
1。先找到磁带机的接口程序才行,不同磁带机的api是不一样的,去磁带机厂商那里去看看<br>2。还有一个办法,利用有些系统支持磁带机的程序,间接的读写,如数据库系统一般都支持<br>这都只是想法,具体你自己去看看吧
 
这里有段代码, 不知道有没有帮助...<br><br>unit TapeCheck;<br><br>{==============================================================================}<br>{ &nbsp; Interface Section &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{==============================================================================}<br><br>interface<br><br>uses SysUtils, Classes, Dialogs, stdctrls, Gauges, messages, Windows, Forms,<br>ComCtrls ;<br><br>TYPE<br>&nbsp;TTapeRecord = record<br>&nbsp; &nbsp;WriteProtect &nbsp; &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; &nbsp;BlockSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;PartitionCount &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; &nbsp;CLP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;CHP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;CQP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;RLP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;RHP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;RQP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp;end;<br><br>TDriveRecord = record<br>&nbsp; &nbsp;ECC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;Compression &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;DataPadding &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;ReportSetMarks &nbsp; &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; &nbsp;DefaultBlockSize &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; &nbsp;MaximumBlockSize &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; &nbsp;MinimumBlockSize &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; &nbsp;MaximumPartitionCount : String;<br>&nbsp; &nbsp;FeaturesLow &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : String;<br>&nbsp; &nbsp;FeaturesHigh &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: String;<br>&nbsp; &nbsp;EOTWarningZoneSize &nbsp; &nbsp;: String;<br>&nbsp;end;<br><br><br><br>&nbsp;TTapeCheck = CLASS(TObject)<br><br><br>private<br><br><br>PUBLIC<br>&nbsp;TapeRecord : TTapeRecord;<br>&nbsp;DriveRecord : TdriveRecord;<br>&nbsp;Constructor create;<br>&nbsp;function uCheckStatus : string;<br>&nbsp;Function TapeStatus : string;<br>&nbsp;Function GetDriveStatus: string;<br>&nbsp;function uRewind : String;<br>&nbsp;function uErase : String;<br>&nbsp;function OpenDrive : THandle;<br>&nbsp;Procedure CloseDrive(TapeHandle : THandle; ms : dword);<br>&nbsp;Function ErrorCodes( eword : dword) : string;<br>&nbsp;procedure SpoolMessages;<br>end; &nbsp;{ Class TtapeCheck }<br><br><br><br><br>{------------------------------------------------------------------------------}<br>{ &nbsp;TAPE_GET_DRIVE_PARAMETERS has not been defined in the VCL as of Delphi 4 &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5.37. If future releases declare it in Windows.pas}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this record could conflict and cause unknown &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errors which should go away if you remove this &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;record. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{------------------------------------------------------------------------------}<br><br>TAPE_GET_DRIVE_PARAMETERS = record<br>&nbsp; &nbsp;ECC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : boolean;<br>&nbsp; &nbsp;Compression &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : boolean;<br>&nbsp; &nbsp;DataPadding &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : boolean;<br>&nbsp; &nbsp;ReportSetMarks &nbsp; &nbsp; &nbsp; &nbsp;: Boolean;<br>&nbsp; &nbsp;DefaultBlockSize &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp;MaximumBlockSize &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp;MinimumBlockSize &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp;MaximumPartitionCount : DWORD;<br>&nbsp; &nbsp;FeaturesLow &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br>&nbsp; &nbsp;FeaturesHigh &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp;EOTWarningZoneSize &nbsp; &nbsp;: DWORD;<br>&nbsp;end;<br><br>{------------------------------------------------------------------------------}<br>{ &nbsp;TAPE_GET_MEDIA_PARAMETERS has not been defined in the VCL as of Delphi 4 &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5.37. If future releases declare it in Windows.pas}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this record could conflict and cause unknown &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errors which should go away if you remove this &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;record. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{------------------------------------------------------------------------------}<br><br>&nbsp;TAPE_GET_MEDIA_PARAMETERS = record<br>&nbsp; &nbsp;Capacity &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: LARGE_INTEGER;<br>&nbsp; &nbsp;Remaining &nbsp; &nbsp; &nbsp; &nbsp; : LARGE_INTEGER;<br>&nbsp; &nbsp;BlockSize &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br>&nbsp; &nbsp;PartitionCount &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp;WriteProtected &nbsp; &nbsp;: BOOLEAN;<br>&nbsp;end;<br><br>{==============================================================================}<br>{ &nbsp; Implementation &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{==============================================================================}<br><br>implementation<br><br>{------------------------------------------------------------------------------}<br>{ Constructor create - Create an instance of TtapeCheck &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{------------------------------------------------------------------------------}<br>Constructor TtapeCheck.create;<br>Begin<br>end;<br><br>{------------------------------------------------------------------------------}<br>{ function uCheckStatus - Tries to open a Tape device and returns an error as &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string if any problem exists &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{------------------------------------------------------------------------------}<br><br>function TtapeCheck.uCheckStatus : string;<br>var<br>&nbsp;TapeHandle : THandle;<br>&nbsp;eword &nbsp; &nbsp; &nbsp;: dword;<br>&nbsp;ErrorMsg &nbsp; : string;<br>begin<br>&nbsp;result := '';<br>&nbsp;{ open the Tape drive }<br>&nbsp;TapeHandle := OpenDrive;<br><br>&nbsp;if Tapehandle = 0 then<br>&nbsp;begin<br>&nbsp; &nbsp;result := 'Unable to find tape drive on system or tape drive in use';<br>&nbsp; &nbsp;Exit;<br>&nbsp;end;<br><br>&nbsp;eword := GetTapeStatus(TapeHandle);<br>&nbsp;SpoolMessages;<br><br><br>&nbsp;ErrorMsg := ErrorCodes(eword);<br>&nbsp;if Length(ErrorMsg) &gt; 0 then<br>&nbsp; &nbsp;Result := ErrorMsg;<br><br>&nbsp;CloseDrive(TapeHandle,10000);<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ &nbsp;TapeStatus - Function retrieves information that describe tape in the drive }<br>{------------------------------------------------------------------------------}<br>FUNCTION TtapeCheck.TapeStatus : &nbsp;string;<br>var<br>&nbsp;eword &nbsp; &nbsp; &nbsp;: dword;<br>&nbsp;dwsize &nbsp; &nbsp; : cardinal;<br>&nbsp;TapeHandle : THandle;<br>&nbsp;TapeInfo &nbsp; : TAPE_GET_MEDIA_PARAMETERS;<br>&nbsp;ErrorMsg &nbsp; : string;<br>begin<br>TapeHandle := OpenDrive;<br><br>&nbsp;if Tapehandle = 0 then<br>&nbsp;begin<br>&nbsp; &nbsp;result := 'Unable to find tape drive on system or tape drive in use';<br>&nbsp; &nbsp;Exit;<br>&nbsp;end;<br><br><br>&nbsp;eword := GetTapeParameters(TapeHandle,GET_TAPE_MEDIA_INFORMATION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwsize,@TapeInfo);<br><br>&nbsp;SpoolMessages;<br><br>&nbsp;if TapeInfo.WriteProtected then<br>&nbsp; &nbsp;TapeRecord.WriteProtect := 'Write Protected = TRUE &nbsp;'<br>&nbsp;else<br>&nbsp; &nbsp;TapeRecord.WriteProtect := 'Write Protected = FALSE &nbsp;';<br><br><br><br>&nbsp;TapeRecord.BlockSize := 'Block Size &nbsp;'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.BlockSize);<br><br>&nbsp;TapeRecord.PartitionCount := 'Partition Count &nbsp;'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.PartitionCount);<br><br>&nbsp;TapeRecord.CLP := 'Capacity Low Part '<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.Capacity.Lowpart);<br><br>&nbsp;TapeRecord.CHP := 'Capacity High Part '<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.Capacity.Highpart);<br><br>&nbsp;TapeRecord.CQP := 'Capacity Quad Part '<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.Capacity.Quadpart);<br><br>&nbsp;TapeRecord.RLP := 'Remaining Low Part '<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.Remaining.Lowpart);<br><br>&nbsp;TapeRecord.RHP := 'Remaining High Part '<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.Remaining.Highpart);<br><br>&nbsp;TapeRecord.RQP := 'Remaining Quad Part '<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.Remaining.Quadpart);<br><br>&nbsp;ErrorCodes(eword);<br>&nbsp;if Length(ErrorMsg) &gt; 0 then<br>&nbsp; &nbsp;Result := ErrorMsg;<br><br>&nbsp;CloseDrive(TapeHandle,1);<br><br>end;<br><br><br>{------------------------------------------------------------------------------}<br>{ &nbsp;GetDriveStatus - Function retrieves information that describe tape drive &nbsp; &nbsp;}<br>{------------------------------------------------------------------------------}<br>function TtapeCheck.GetDriveStatus : string;<br>var<br>&nbsp;eword &nbsp; &nbsp; &nbsp; : dword;<br>&nbsp;dwsize &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp;TapeHandle &nbsp;: THandle;<br>&nbsp;TapeInfo &nbsp; &nbsp;: TAPE_GET_DRIVE_PARAMETERS;<br>&nbsp;ErrorMsg &nbsp; &nbsp;: string;<br>begin<br>&nbsp;TapeHandle := OpenDrive;<br><br>&nbsp;if Tapehandle = 0 then<br>&nbsp; &nbsp;Exit;<br><br><br>&nbsp;eword := GetTapeParameters(TapeHandle,GET_TAPE_DRIVE_INFORMATION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwsize,@TapeInfo);<br>&nbsp;SpoolMessages;<br><br>&nbsp;if TapeInfo.ECC then<br>&nbsp; &nbsp; DriveRecord.ECC := 'Error Control = TRUE &nbsp;'<br>&nbsp;else<br>&nbsp; &nbsp; DriveRecord.ECC := 'Error Control = FALSE &nbsp;';<br><br>&nbsp;if TapeInfo.Compression then<br>&nbsp; &nbsp; DriveRecord.Compression := 'Compression = TRUE &nbsp;'<br>&nbsp;else<br>&nbsp; &nbsp; DriveRecord.Compression :='Compression = FALSE &nbsp;';<br><br>&nbsp; if TapeInfo.DataPadding then<br>&nbsp; &nbsp; DriveRecord.DataPadding := 'Data Padding = TRUE &nbsp;'<br>&nbsp;else<br>&nbsp; &nbsp; DriveRecord.DataPadding := 'Data Padding = FALSE &nbsp;';<br><br>&nbsp;if TapeInfo.ReportSetMarks then<br>&nbsp; &nbsp;DriveRecord.ReportSetMarks := 'Report Set Marks = TRUE &nbsp;'<br>&nbsp;else<br>&nbsp; &nbsp;DriveRecord.ReportSetMarks := 'Report Set Marks = FALSE &nbsp;';<br><br>&nbsp;DriveRecord.DefaultBlockSize := 'Default Block Size &nbsp;' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntToStr(TapeInfo.DefaultBlockSize);<br><br><br>&nbsp;DriveRecord.MaximumBlockSize := 'Maximum Block Size &nbsp;'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.MaxiMumBlockSize);<br><br>&nbsp;DriveRecord.MinimumBlockSize := 'Minimum Block Size &nbsp;'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IntToStr(TapeInfo.MinimumBlockSize);<br><br>&nbsp;DriveRecord.MaximumPartitionCount := 'Maximum Partition Count &nbsp;' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IntToStr(TapeInfo.MaxiMumPartitionCount);<br><br>&nbsp;DriveRecord.FeaturesLow :='Features Low &nbsp;' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntToStr(TapeInfo.FeaturesLow);<br><br>&nbsp;DriveRecord.FeaturesHigh := 'Features High &nbsp;' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntToStr(TapeInfo.FeaturesHigh);<br><br>&nbsp;DriveRecord.EOTWarningZoneSize := 'EOT Warning Zone Size &nbsp;' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntToStr(TapeInfo.EOTWarningZoneSize);<br><br><br>&nbsp; &nbsp;ErrorCodes(eword);<br>&nbsp; &nbsp;if Length(ErrorMsg) &gt; 0 then<br>&nbsp; &nbsp; &nbsp;Result := ErrorMsg;<br><br>&nbsp;CloseDrive(TapeHandle,1);<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ &nbsp;uRewind - Rewinds the current tape in the machine. Returns any error as a &nbsp; }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{------------------------------------------------------------------------------}<br>function TtapeCheck.uRewind : string;<br>var<br>&nbsp;TapeHandle &nbsp;: THandle;<br>&nbsp;eword &nbsp; &nbsp; &nbsp; : dword;<br>&nbsp;TAPE_REWIND : LongInt;<br>&nbsp;ErrorMsg &nbsp; &nbsp;: string;<br>begin<br>&nbsp;result := '';<br>&nbsp;{ open the existing file for reading }<br>&nbsp;TapeHandle := OpenDrive;<br><br>&nbsp;if Tapehandle = 0 then<br>&nbsp;begin<br>&nbsp; &nbsp;result := 'Unable to find tape drive on system or tape drive in use';<br>&nbsp; &nbsp;Exit;<br>&nbsp;end;<br><br>&nbsp;TAPE_REWIND := 0;<br><br>&nbsp;eword := SetTapePosition(TapeHandle,TAPE_REWIND,0,0,0,TRUE);<br>&nbsp;SpoolMessages;<br><br><br>&nbsp;CloseDrive(TapeHandle,10000);<br><br>&nbsp;ErrorMsg := ErrorCodes(eword);<br>&nbsp;if Length(ErrorMsg) &gt; 0 then<br>&nbsp; &nbsp;Result := ErrorMsg;<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ &nbsp;uErase - Will erase tape in the drive. Returns any error as a string &nbsp; &nbsp; &nbsp; &nbsp;}<br>{------------------------------------------------------------------------------}<br>Function TtapeCheck.uErase : string;<br>var<br>&nbsp;TapeHandle : THandle;<br>&nbsp;eword &nbsp; &nbsp; &nbsp;: dword;<br>&nbsp;ErrorMsg &nbsp; : String;<br>begin<br>&nbsp;result := '';<br>&nbsp;{ open the tape drive }<br><br>&nbsp;TapeHandle := OpenDrive;<br><br>&nbsp;if Tapehandle = 0 then<br>&nbsp;begin<br>&nbsp; &nbsp;result := 'Unable to find tape drive on system or tape drive in use';<br>&nbsp; &nbsp;Exit;<br>&nbsp;end;<br><br>&nbsp;eword := EraseTape(TapeHandle,0,TRUE);<br>&nbsp;SpoolMessages;<br><br>&nbsp;ErrorMsg := ErrorCodes(eword);<br>&nbsp;if Length(ErrorMsg) &gt; 0 then<br>&nbsp; &nbsp;Result := ErrorMsg;<br><br>&nbsp;CloseDrive(TapeHandle,10000);<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ OpenDrive - Opens the default tape drive on the system. Returns the handle &nbsp; }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; of the tape device. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{------------------------------------------------------------------------------}<br><br>function TtapeCheck.OpenDrive : THandle;<br>var<br>&nbsp;TapeHandle : THandle;<br>&nbsp;Security : TSecurityAttributes;<br>begin<br>&nbsp;Security.nLength := SizeOf(TSecurityAttributes);<br>&nbsp;Security.bInheritHandle := FALSE;<br>&nbsp;Security.lpSecurityDescriptor := nil;<br>&nbsp;TapeHandle := CreateFile('/.TAPE0', GENERIC_READ OR GENERIC_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FILE_SHARE_READ OR FILE_SHARE_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@SECURITY,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING, 0, 0);<br><br>&nbsp;{ indicate an error if the tape drive does not exist }<br>&nbsp;if TapeHandle=INVALID_HANDLE_VALUE then<br>&nbsp; &nbsp;result := 0<br>&nbsp;else<br>&nbsp; &nbsp;result := tapeHandle;<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ CloseDrive - procedure to close a tape handle &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{------------------------------------------------------------------------------}<br><br>Procedure TtapeCheck.CloseDrive(TapeHandle : THandle; ms : dword);<br>begin<br>&nbsp;sleep(ms); &nbsp;{ allow time for tape drive to reset before close }<br>&nbsp;closehandle(TapeHandle);<br>end;<br><br><br>{------------------------------------------------------------------------------}<br>{ Function ErrorCodes - Converts error code value to a description and returns }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; it as a string. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{------------------------------------------------------------------------------}<br><br>Function TtapeCheck.ErrorCodes( eword : dword) : string;<br>begin<br>&nbsp;if eword = ERROR_MEDIA_CHANGED then eword := 0;<br>&nbsp;if eword = ERROR_BUS_RESET then eword := 0;<br>&nbsp;if eword = 0 then<br>&nbsp; &nbsp;result := '';<br><br>&nbsp;if eword = 1 then<br>&nbsp; &nbsp;result := 'This Tape drive does not support this function';<br><br>&nbsp;if eword = ERROR_FILE_NOT_FOUND then &nbsp; &nbsp;{ &nbsp;2 }<br>&nbsp; &nbsp;result := 'The system cannot find the file specified. ';<br><br>&nbsp;if eword = ERROR_PATH_NOT_FOUND then &nbsp; &nbsp; { 3 }<br>&nbsp; &nbsp;result := 'The system cannot find the path specified. ';<br><br>&nbsp;if eword = ERROR_TOO_MANY_OPEN_FILES then { 4 }<br>&nbsp; &nbsp;result := 'The system cannot open the file. ';<br><br>&nbsp;if eword = ERROR_ACCESS_DENIED then &nbsp; &nbsp; &nbsp;{ &nbsp;5 }<br>&nbsp; &nbsp;result := 'Access is denied. ';<br><br>&nbsp;if eword = ERROR_INVALID_HANDLE then &nbsp; &nbsp; { &nbsp;6 }<br>&nbsp; &nbsp;result := 'The handle is invalid. ';<br><br>&nbsp;if eword = ERROR_ARENA_TRASHED then &nbsp; &nbsp; &nbsp;{ &nbsp;7 }<br>&nbsp; &nbsp;result := 'The storage control blocks were destroyed. ';<br><br>&nbsp;if eword = ERROR_NOT_ENOUGH_MEMORY then &nbsp;{ 8 &nbsp;}<br>&nbsp; &nbsp;result := 'Not enough storage is available to process this command. ';<br><br>&nbsp;if eword = ERROR_INVALID_BLOCK then &nbsp; &nbsp; &nbsp;{ 9 &nbsp;}<br>&nbsp; &nbsp;result := 'The storage control block address is invalid. ';<br><br>&nbsp;if eword = ERROR_BAD_ENVIRONMENT then { 10 }<br>&nbsp; &nbsp;result := 'The environment is incorrect. ';<br><br>&nbsp;if eword = ERROR_BAD_FORMAT then &nbsp; &nbsp; &nbsp;{ 11 }<br>&nbsp; &nbsp;result := 'An attempt was made to load a program with an incorrect format.';<br><br>&nbsp;if eword = ERROR_INVALID_ACCESS then &nbsp;{ 12 }<br>&nbsp; &nbsp;result := 'The access code is invalid. ';<br><br>&nbsp;if eword = ERROR_INVALID_DATA then &nbsp; &nbsp;{ 13 }<br>&nbsp; &nbsp;result := 'The data is invalid. ';<br><br>&nbsp;if eword = ERROR_OUTOFMEMORY then &nbsp; &nbsp; { 14 }<br>&nbsp; &nbsp;result := 'Not enough storage is available to complete the operation. ';<br><br>&nbsp;if eword = ERROR_INVALID_DRIVE then &nbsp; { 15 }<br>&nbsp; &nbsp;result := 'The system cannot find the drive specified. ';<br><br>&nbsp;if eword = ERROR_CURRENT_DIRECTORY then &nbsp;{ 16 }<br>&nbsp; &nbsp;result := 'The directory cannot be removed. ';<br><br>&nbsp;if eword = ERROR_NOT_SAME_DEVICE then &nbsp; &nbsp;{ 17 }<br>&nbsp; &nbsp;result := 'The system cannot move the file to a different disk drive. ';<br><br>&nbsp;if eword = ERROR_NO_MORE_FILES then &nbsp; &nbsp; { 18 }<br>&nbsp; &nbsp;result := 'There are no more files. ';<br><br>&nbsp;if eword = ERROR_WRITE_PROTECT then &nbsp; &nbsp; &nbsp;{ 19 }<br>&nbsp; &nbsp;result := 'Error, The write protect is set ';<br><br>&nbsp;if eword = ERROR_BAD_UNIT then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ 20 }<br>&nbsp; &nbsp;result := 'Error, The system cannot find the device ';<br><br>&nbsp;if eword = ERROR_NOT_READY then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ 21 }<br>&nbsp; &nbsp;result := 'The device is not ready ';<br><br>&nbsp;if eword = ERROR_BAD_COMMAND then &nbsp;{ 22 }<br>&nbsp; &nbsp; result := 'The device does not recognize the command. ';<br><br>&nbsp;if eword = ERROR_CRC then &nbsp;{ 23 }<br>&nbsp; &nbsp; result := 'Data error (cyclic redundancy check). ';<br><br>&nbsp;if eword = ERROR_BAD_LENGTH then{ 24 }<br>&nbsp; &nbsp; result := 'Incorrect command length from program ';<br><br>&nbsp;if eword = ERROR_SEEK then &nbsp;{ 25 }<br>&nbsp; &nbsp; result := 'The drive cannot locate a specfic area or track on the disk ';<br><br>&nbsp;if eword = ERROR_NOT_DOS_DISK then { 26 }<br>&nbsp; &nbsp; result := 'The specified disk or diskette cannot be accessed. ';<br><br>&nbsp;if eword = ERROR_SECTOR_NOT_FOUND then { 27 }<br>&nbsp; &nbsp; result := 'The drive cannot find the sector requested. ';<br><br>&nbsp;if eword = ERROR_OUT_OF_PAPER then &nbsp;{ 28 }<br>&nbsp; &nbsp; result := 'The Printer is out of paper. ';<br><br>&nbsp;if eword = ERROR_WRITE_FAULT then { 29 }<br>&nbsp; &nbsp; result := 'The system cannot read from the specified device. ';<br><br>&nbsp;if eword = ERROR_READ_FAULT then { 30 }<br>&nbsp; &nbsp; result := 'The system cannot read from the specified device. ';<br><br>&nbsp;if eword = ERROR_GEN_FAILURE then { 31 }<br>&nbsp; &nbsp; result := 'A device attached to the system is not functioning. ';<br><br>&nbsp;if eword = ERROR_SHARING_VIOLATION then { 32 }<br>&nbsp; &nbsp; result := 'The file is being using by another process. ';<br><br>&nbsp;if eword = ERROR_LOCK_VIOLATION then { 33 }<br>&nbsp; &nbsp; result := 'Another process has locked the file. ';<br><br>&nbsp;if eword = ERROR_WRONG_DISK then &nbsp;{ 34 }<br>&nbsp; &nbsp; result := 'The wrong diskette is in the drive. ';<br><br>&nbsp;if eword = ERROR_SHARING_BUFFER_EXCEEDED then{ 36 }<br>&nbsp; &nbsp; result := 'Too many files opened for sharing. ';<br><br>&nbsp;if eword = ERROR_HANDLE_EOF then &nbsp; &nbsp; &nbsp; &nbsp; { 38 }<br>&nbsp; &nbsp; result := 'Reached end of file ';<br><br>&nbsp;if eword = ERROR_HANDLE_DISK_FULL then { 39 }<br>&nbsp; &nbsp; result := 'The disk is full ';<br><br>&nbsp;if eword = ERROR_NOT_SUPPORTED then { 50 }<br>&nbsp; &nbsp;result := 'The network request is not supported. ';<br><br>&nbsp;if eword = ERROR_MORE_DATA then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ 234 }<br>&nbsp; &nbsp;result := 'More data is available ';<br><br>&nbsp;if eword = ERROR_END_OF_MEDIA then &nbsp; &nbsp;{ 1100 }<br>&nbsp; &nbsp;result := 'Error, End of media ';<br><br>&nbsp;if eword = ERROR_FILEMARK_DETECTED then &nbsp;{ 1101 }<br>&nbsp; &nbsp;result := 'Error, Filemark detected ';<br><br>&nbsp;if eword = ERROR_BEGINNING_OF_MEDIA then &nbsp; { 1102 }<br>&nbsp; &nbsp;result := 'Error, Cannot access data before medium marker ';<br><br>&nbsp;if eword = ERROR_SETMARK_DETECTED then &nbsp; { 1103 }<br>&nbsp; &nbsp;result := 'Error, A setmark was reached ';<br><br>&nbsp;if eword = ERROR_NO_DATA_DETECTED then &nbsp; { 1104 }<br>&nbsp; &nbsp;result := 'Error, Eof of data marker reached ';<br><br>&nbsp;if eword = ERROR_PARTITION_FAILURE then &nbsp; { 1105 }<br>&nbsp; &nbsp;result := 'Error, The tape could not be partitioned ';<br><br>&nbsp;if eword = ERROR_INVALID_BLOCK_LENGTH then &nbsp; { 1106 }<br>&nbsp; &nbsp;result := 'Error, The Block size is incorrect ';<br><br>&nbsp;if eword = ERROR_DEVICE_NOT_PARTITIONED then &nbsp; { 1107 }<br>&nbsp; &nbsp;result := 'Error, Partition information not found ';<br><br>&nbsp;if eword = ERROR_UNABLE_TO_LOCK_MEDIA then &nbsp; { 1108 }<br>&nbsp; &nbsp;result := 'Error, An attempt to lock the ejection mechanism failed ';<br><br>&nbsp;if eword = ERROR_UNABLE_TO_UNLOAD_MEDIA then &nbsp; { 1109 }<br>&nbsp; &nbsp;result := 'Error, An attempt to unload the media failed &nbsp;';<br><br>&nbsp;if eword = ERROR_MEDIA_CHANGED then &nbsp; { 1110 }<br>&nbsp; &nbsp;result := 'Error, The tape in the drive has been replaced. &nbsp;' +<br>&nbsp; ' This tape drive may be type QIC which is not supported. ';<br><br>&nbsp;if eword = ERROR_BUS_RESET then &nbsp; { 1111 }<br>&nbsp; &nbsp;result := 'Error, A reset condition was detected on the bus ';<br><br>&nbsp;if eword = ERROR_NO_MEDIA_IN_DRIVE then &nbsp; { 1112 }<br>&nbsp; &nbsp;result := 'There is no media in the drive ';<br><br>end;<br><br>{------------------------------------------------------------------------------}<br>{ SpoolMessages - &nbsp;checks a thread message queue for a message and places &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the message (if any) in the specified structure. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Allows screen updates after a task switch and back &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{------------------------------------------------------------------------------}<br><br>procedure TtapeCheck.SpoolMessages;<br>var<br>&nbsp;Msg : TMsg;<br>begin<br>&nbsp;while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do<br>&nbsp;begin<br>&nbsp; &nbsp;TranslateMessage(Msg);<br>&nbsp; &nbsp;DispatchMessage(Msg);<br>&nbsp;end<br><br>end;<br><br>&nbsp; &nbsp; { its the end of the world as we know it. }<br>end.
 
看 SDK。
 
顶部