Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.06.17;
Скачать: CL | DM;

Вниз

Лишняя инфа   Найти похожие ветки 

 
Ламонов Олег   (2007-04-21 11:11) [0]

Уважаемые мастера.
Добавляется лишняя информация в файл, как ее удалить?

var
 MainHeaderFile:PHeader;
 Header:Header_;

type
  PHeader = ^Header_;
  Header_ = packed record
     AssociateProgram:string[30];
     MainType:string[50];
     Version:string[10];
     Description:string[255];
     Comments:string[255];
end;

function TMyFile.CreateFile_(const AName:string):Boolean;
var
  Buf:file;
begin
  if FileExists(AName) = True then
  begin
     Result:=True
   end else
  begin
     AssignFile(Buf, AName);
     {$I-}
     Rewrite(Buf,1);
     {I-}
//      FIndex:=OpenFile(PChar(AName),ofStructF,of_ReadWrite or of_Share_Exclusive);

     New(MainHeaderFile);
     MainHeaderFile^.AssociateProgram:=(Application.Title);
     MainHeaderFile^.MainType:=MainExtension;
     MainHeaderFile^.Version:=VersionA;
     MainHeaderFile^.Description:=QualityLive;
     MainHeaderFile^.Comments:=Special;
     BlockWrite(Buf,MainHeaderFile^,Sizeof(MainHeaderFile^));
     Dispose(MainHeaderFile);

Здесь он добавляет лишнее, через Header все Ok.

   {  Header.AssociateProgram:=Application.Title;
     Header.MainType:=MainExtension;
     Header.Version:=VersionA;
     Header.Description:=QualityLive;
     Header.Comments:=Special;
     BlockWrite(Buf,Header,Sizeof(Header));
    }

     FlushFileBuffers(TFileRec(Buf).Handle);
     FileClose(FIndex);
     Result:=False;
  end;


 
Loginov Dmitry ©   (2007-04-21 13:58) [1]

> var
> MainHeaderFile:PHeader;
> Header:Header_;
>
> type
>  PHeader = ^Header_;
>  Header_ = packed record
>     AssociateProgram:string[30];
>     MainType:string[50];
>     Version:string[10];
>     Description:string[255];
>     Comments:string[255];
> end;


Не компилицца.


>     FileClose(FIndex);


Как все перемешано! Чем не устроило CloseFile(Buf)?


> Добавляется лишняя информация в файл, как ее удалить?


Сразу после New(MainHeaderFile); делай ZeroMemory. В структуре все поля статические, так что это можно.


 
Loginov Dmitry ©   (2007-04-21 14:16) [2]

Кстати, в случае с Header также мусор получишь, если выполнишь несколько раз присвоение одному полю строк разной длины. Просто в самый первый раз мусора нет, так как содержимое глобального объекта при запуске проги автоматически обнуляется.


 
Ламонов Олег   (2007-04-22 08:09) [3]

Все равно остается мусор.
ZeroMemory(MainHeaderFile,Sizeof(MainHeaderFile));


 
Loginov Dmitry ©   (2007-04-22 09:09) [4]

ZeroMemory(MainHeaderFile,Sizeof(Header_));



Страницы: 1 вся ветка

Текущий архив: 2007.06.17;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.019 c
2-1180438381
s_t_d
2007-05-29 15:33
2007.06.17
TP 7.1. Вывод на экран двумерного массива по строкам


3-1174998768
rm
2007-03-27 16:32
2007.06.17
оптимизация работы с БД


2-1180017749
Skylp
2007-05-24 18:42
2007.06.17
Размеры формы в зависемости от разрешения!!


10-1132635470
Simon
2005-11-22 07:57
2007.06.17
Печать Excel


2-1180123811
Dmitry_177
2007-05-26 00:10
2007.06.17
оператор case