Этот баннер — требование Роскомнадзора для исполнения 152 ФЗ.
«На сайте осуществляется обработка файлов cookie, необходимых для работы сайта, а также для анализа использования сайта и улучшения предоставляемых сервисов с использованием метрической программы Яндекс.Метрика. Продолжая использовать сайт, вы даёте согласие с использованием данных технологий».
Политика конфиденциальности
|
|
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Надо создать свой формат файла , например *.pg структура файла TMyfile = record ID:integer; end; Сохранить его на диске с расширением *.pg, чтобы потом можно было открыть его редактором. Объясняю для чего. Существует объект БД. Файл будет выполнять роль указателя на этот объект в файловой структуре. При обработке этого файла редактором, он должен извлечь из него ID, обратиться к БД и получить данные об объекте БД. Все. Подскажите пути решения. Не знаю как создать, сохранить и прочитать этот файл... Заранее благодарен. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 09:58 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
FileCreate FileRead FileWrite FileClose ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 10:06 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Delphi Help > Index > file management routines ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 10:06 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Посмотрите, что не так? Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 10:44 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
FileRead|FileWrite нужно передавать указатель на данные. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 10:46 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
А как их передавать? FileWrite(FileHandle,Pointer(Data),SizeOf(Data)); или FileWrite(FileHandle,^Data,SizeOf(Data)); не прокатывает... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 10:55 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Delphi Help > Index > file management routines там екзамплы на абсолютно все функции... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 11:01 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Уважаемый KirillovA. Там есть пример записи в файл строки и прочей чешуи. Мне надо сохранить структуру TMyfile = record ID:integer; Name:string; end; Я понимаю, что все так же как и с обычной строкой, но почему не считывается значение при Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. понять не могу... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 11:07 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Voobsse ja bi delal kak v helpe: type PhoneEntry = record FirstName, LastName: string[20]; PhoneNumber: string[15]; Listed: Boolean; end; PhoneList = file of PhoneEntry; ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 11:26 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Точно не помню как это выглядит в Паскале (читай справку), но примерно так: Код: plaintext ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 11:39 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
VCL Reference FileExists, RenameFile, FileCreate, FileWrite, FileClose, ExtractFileName Example The following example uses a button, a string grid, and a Save dialog box on a form. When the button is clicked, the user is prompted for a filename. When the user clicks OK, the contents of the string grid are written to the specified file. Additional information is also written to the file so that it can be read easily with the FileRead function. procedure TForm1.Button1Click(Sender: TObject); var BackupName: string; FileHandle: Integer; StringLen: Integer; X: Integer; Y: Integer; begin if SaveDialog1.Execute then begin if FileExists(SaveDialog1.FileName) then begin BackupName := ExtractFileName(SaveDialog1.FileName); BackupName := ChangeFileExt(BackupName, '.BAK'); if not RenameFile(SaveDialog1.FileName, BackupName) then raise Exception.Create('Unable to create backup file.'); end; FileHandle := FileCreate(SaveDialog1.FileName); { Write out the number of rows and columns in the grid. } FileWrite(FileHandle, StringGrid1.ColCount, SizeOf(StringGrid1.ColCount)); FileWrite(FileHandle, StringGrid1.RowCount, SizeOf(StringGrid1.RowCount)); for X := 0 to StringGrid1.ColCount – 1 do begin for Y := 0 to StringGrid1.RowCount – 1 do begin { Write out the length of each string, followed by the string itself. } StringLen := Length(StringGrid1.Cells[X,Y]); FileWrite(FileHandle, StringLen, SizeOf(StringLen)); FileWrite(FileHandle, StringGrid1.Cells[X,Y], Length(StringGrid1.Cells[X,Y]); end; end; FileClose(FileHandle); end; end; --------------------------------------------------- VCL Reference FileSeek function See also Example Repositions read/write point. Unit SysUtils Category file management routines function FileSeek(Handle, Offset, Origin: Integer): Integer; overload; function FileSeek(Handle: Integer; const Offset: Int64; Origin: Integer): Int64; overload; Description Use FileSeek to reposition the read/write point in a file that was opened with FileOpen or FileCreate. Handle is the file handle that was returned by FileOpen or FileCreate. Offset specifies the number of bytes from Origin where the file pointer should be positioned. Origin is a code with three possible values, denoting the beginning of the file, the end of the file, and the current position of the file pointer. Origin Action 0 The file pointer is positioned Offset bytes from the beginning of the file. 1 The file pointer is positioned Offset bytes from its current position. 2 The file pointer is positioned Offset bytes from the end of the file. If FileSeek is successful, it returns the new position of the file pointer; otherwise, it returns -1. Note: Do not mix routines that take or return file handles with those that use Pascal file variables (typically seen as var F). To move the file pointer in a file specified by a Pascal file variable, use the Seek procedure instead. VCL Reference FileOpen, FileSeek, FileRead Example The following example uses a button, a string grid, and an Open dialog box on a form. When the button is clicked, the user is prompted for a filename. When the user clicks OK, the specified file is opened, read into a buffer, and closed. Then the buffer is displayed in two columns of the string grid. The first column contains the character values in the buffer. The second column contains the numeric values of the characters in the buffer. procedure TForm1.Button1Click(Sender: TObject); var iFileHandle: Integer; iFileLength: Integer; iBytesRead: Integer; Buffer: PChar; i: Integer begin if OpenDialog1.Execute then begin try iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead); iFileLength := FileSeek(iFileHandle,0,2); FileSeek(iFileHandle,0,0); Buffer := PChar(AllocMem(iFileLength + 1)); iBytesRead := FileRead(iFileHandle, Buffer, iFileLength); FileClose(iFileHandle); for i := 0 to iBytesRead-1 do begin StringGrid1.RowCount := StringGrid1.RowCount + 1; StringGrid1.Cells[1,i+1] := Buffer ; StringGrid1.Cells[2,i+1] := IntToStr(Integer(Buffer)); end; finally FreeMem(Buffer); end; end; end; ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 12:34 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Можно юзать связку еще с досовского паскаля Write фор типизед файлес и Seek и Read и все такое - короче екзамплы гляди по ним.... а то адми мне башку за спуффинг оторвет ... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 12:36 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2003, 14:21 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Спасибо конечно, Олег! Но что то не считывает... ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.06.2003, 06:52 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
> что то не считывает... ну еще бы! Вы не пробовали посмотреть, чему равно SizeOf(Data)? ;) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.06.2003, 11:04 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.06.2003, 11:05 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
вдогонку. Если в структуре должны быть строковые данные - указывайте их размер: name: string[20] ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.06.2003, 11:10 |
|
||
|
Свой формат файла
|
|||
|---|---|---|---|
|
#18+
Dmitri Krizhanovski О Г Р О М Н О Е С П А С И Б О ! ! ! Прям как камень с души ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.06.2003, 14:34 |
|
||
|
|

start [/forum/topic.php?fid=58&msg=32172564&tid=2118120]: |
0ms |
get settings: |
10ms |
get forum list: |
18ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
30ms |
get topic data: |
11ms |
get forum data: |
3ms |
get page messages: |
66ms |
get tp. blocked users: |
1ms |
| others: | 261ms |
| total: | 408ms |

| 0 / 0 |
