![]() |
#1 |
Участник
|
Запись в бинарный файл
Столкнулся с такой задачей: нужно в файл базы данных DBF записать 1 байт с 28 позиции - чтобы игнорировать индексы. На визуал бейсике это сделать легко:
Open FilePath For Binary As #1 Put #1, 29 , CByte(0) 'Байт со смещением 28 (по счету - 29-й) Close #1 А вот как на аксапте? BinaryIO не подходит, BinData может быть? Если можно кусок кода. Спасибо за внимание. ![]() PS. Может кто знает как через ConnectionString или еще как нибудь можно удалить либо игнорить индекс для базы данных MDX Последний раз редактировалось CHESER85; 08.08.2012 в 15:56. Причина: поскриптум |
|
![]() |
#2 |
Участник
|
программеры где вы! ау.
|
|
![]() |
#3 |
Участник
|
методом активного интернет-поиска нашел решение:
X++: static void Jobik(Args _args) { BinData B = new BinData(); array a = new array(types::Enum); comvariant var1; ; B.loadFile("c:\\temp\\old_file.dbf"); var1 = b.getVariant(); a=var1.safeArray(); a.value(29,0); var1.safeArray(a); b.setVariant(var1); B.SaveFile("c:\\temp\\new_file.dbf"); } |
|
![]() |
#4 |
Участник
|
System.IO.FileStream.WriteByte Method, если у вас 4.0 и выше.
|
|
![]() |
#5 |
Участник
|
на ax 4.0 нет такого класса и using не является зарезервированным словом
![]() |
|
![]() |
#6 |
Участник
|
|
|
![]() |
#7 |
Участник
|
|
|
![]() |
#8 |
Участник
|
X++: client static int _lOpen(str fileName, int readWrite) { DLL _dll = new DLL("Kernel32.dll"); DLLFunction _iOpen = new DLLFunction(_dll, "_lOpen"); ; _lOpen.arg(ExtTypes::WString, ExtTypes:: DWORD); _lOpen.returns(ExtTypes:: DWORD); return _lOpen.call(fileName, readWrite); } client static int _lRead(int fHandle, Binary buff, int bytes) { DLL _dll = new DLL("Kernel32.dll"); DLLFunction _lRead = new DLLFunction(_dll, "_lRead"); ; _lRead.arg(ExtTypes:: DWORD, ExtTypes::Pointer, ExtTypes:: DWORD); _lRead.returns(ExtTypes::Word); return _lRead.call(fHandle, buff, bytes); } С уважением, Дмитрий. Последний раз редактировалось DmitryK; 09.08.2012 в 08:26. |
|
![]() |
#9 |
Участник
|
Цитата:
Сообщение от DmitryK
![]() client static int _iOpen(str fileName, int readWrite)
{ DLL _dll = new DLL("Kernel32.dll"); DLLFunction _iOpen = new DLLFunction(_dll, "_iOpen"); ; _iOpen.arg(ExtTypes::WString, ExtTypes: ![]() _iOpen.returns(ExtTypes:: DWORD); return _iOpen.call(fileName, readWrite); } client static int _lRead(int fHandle, Binary buff, int bytes) { DLL _dll = new DLL("Kernel32.dll"); DLLFunction _lRead = new DLLFunction(_dll, "_lRead"); ; _lRead.arg(ExtTypes: ![]() ![]() _lRead.returns(ExtTypes::Word); return _lRead.call(fHandle, buff, bytes); } Как то так. К сожалению, проверить сейчас не могу. С уважением, Дмитрий. |
|
![]() |
#10 |
Участник
|
Что именно не помогает?
C уважением, Дмитрий . |
|
![]() |
#11 |
Участник
|
|
|
|
За это сообщение автора поблагодарили: SRF (1). |
![]() |
#12 |
Участник
|
Короче добился я своей цели, правда огромными усилиями. Использовал функции, написанные в проектах Andy_D и Yegor (DBF без ODBC).
И самое главное - это работает! и работает быстро. #winapi #DEFINE.FILE_SHARE_READ(0x00000001) #DEFINE.FILE_SHARE_WRITE(0x00000002) #DEFINE.FILE_SHARE(#FILE_SHARE_READ | #FILE_SHARE_WRITE) #define.FILE_FLAG_RANDOM_ACCESS(0x10000000) #define.FILE_BEGIN (0) protected void DisableIndex(FileName fileName) { int hFile; binary Value = new Binary(1); int createFile() { DLL _winApiDLL = new DLL('KERNEL32'); DLLFunction _createFile = new DLLFunction(_winApiDLL, 'CreateFileA'); ; _createFile.returns(ExtTypes: ![]() _createFile.arg(ExtTypes::String); // lpFileName _createFile.arg(ExtTypes: ![]() _createFile.arg(ExtTypes: ![]() _createFile.arg(ExtTypes: ![]() _createFile.arg(ExtTypes: ![]() _createFile.arg(ExtTypes: ![]() _createFile.arg(ExtTypes: ![]() return _createFile.call(fileName, #GENERIC_WRITE, #FILE_SHARE, 0, #OPEN_EXISTING, #FILE_FLAG_RANDOM_ACCESS, 0); } void writeFile(int hWnd, Binary Buffer, int size) { DLL _winApiDLL = new DLL('KERNEL32'); DLLFunction _writeFile = new DLLFunction(_winApiDLL, 'WriteFile'); int Result; Binary RetValue = new Binary(4); int Temp; _writeFile.returns(ExtTypes: ![]() _writeFile.arg(ExtTypes: ![]() _writeFile.arg(ExtTypes::Pointer); _writeFile.arg(ExtTypes: ![]() _writeFile.arg(ExtTypes::Pointer); _writeFile.arg(ExtTypes: ![]() Temp = _writeFile.call(hWnd,Buffer,size,RetValue,0); info(int2str(RetValue.dWord(0))); if (Temp == 0) { throw error("Функция WriteFile вернула ошибку " + int2str(WinApi::getLastError())); } Result = RetValue.byte(0) + RetValue.byte(1)*256 + RetValue.byte(2)*256*256 + RetValue.byte(3)*256*256*256; if (Result != size) { throw error("Функция WriteFile вызвала ошибку записи в файл"); } } int setFilePointer(int handle, int distancel, int moveMethod) { DLL _winApiDLL = new DLL('KERNEL32'); DLLFunction _setFilePointer = new DLLFunction(_winApiDLL, 'SetFilePointer'); _setFilePointer.returns(ExtTypes: ![]() _setFilePointer.arg(ExtTypes: ![]() ![]() ![]() ![]() if (_setFilePointer.call(handle, distancel, 0 , moveMethod) == 0) return WinApi::getLastError(); else return 0; } ; hFile = createFile(); if (hFile != #INVALID_HANDLE_VALUE) { setFilePointer(hfile, 28, #FILE_BEGIN); value.byte(0,0); writeFile(hfile, value, 1); Winapi::closeHandle(hFile); } } Последний раз редактировалось CHESER85; 09.08.2012 в 09:28. |
|
![]() |
#13 |
Участник
|
Многобукаф
X++: System.IO.FileStream fileStream; ; new InteropPermission(InteropKind::ClrInterop).assert(); try { fileStream = new System.IO.FileStream(@"C:\temp\test.bin", System.IO.FileMode::Open, System.IO.FileAccess::Write, System.IO.FileShare::Read); fileStream.Seek(28, System.IO.SeekOrigin::Begin); fileStream.WriteByte(System.Convert::ToByte(0xff)); fileStream.Close(); fileStream.Dispose(); } catch (Exception::CLRError) { throw error(AifUtil::getClrErrorMessage()); } |
|
|
За это сообщение автора поблагодарили: GBH (1), someOne (3). |
![]() |
#14 |
Участник
|
Цитата:
Сообщение от gl00mie
![]() Многобукаф
X++: System.IO.FileStream fileStream; ; new InteropPermission(InteropKind::ClrInterop).assert(); try { fileStream = new System.IO.FileStream(@"C:\temp\test.bin", System.IO.FileMode::Open, System.IO.FileAccess::Write, System.IO.FileShare::Read); fileStream.Seek(28, System.IO.SeekOrigin::Begin); fileStream.WriteByte(System.Convert::ToByte(0xff)); fileStream.Close(); fileStream.Dispose(); } catch (Exception::CLRError) { throw error(AifUtil::getClrErrorMessage()); } к сожалению не работает в 4.0 ![]() |
|
![]() |
#15 |
Участник
|
Уровень детализации, с которым вы описываете (не)работу того или иного примера кода, просто поражает
![]() |
|
![]() |
#16 |
Участник
|
ну не компилится код. аксапта говорит что не знает этих классов и енумов.
|
|
![]() |
#17 |
Участник
|
Ах, да, 4-ка не умеет работать напрямую с CLR-енумами, их нужно заменить в коде X++ на такие вот конструкции:
X++: CLRInterop::parseClrEnum('System.IO.FileMode', 'Open') |
|