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

Вниз

Сохранение в файл   Найти похожие ветки 

 
Creative   (2006-05-19 12:43) [0]

Как, используя только функции WinApi, сохранить в файл список строк (string) разной длины и потом корректно его загрузить?


 
Desdechado ©   (2006-05-19 12:46) [1]

в winapi нет строк
загрузить куда?

CreateFile Creates, opens or truncates a file
OpenFile Creates, opens or deletes a file
WriteFile Writes data to file or device
WriteFileEx Writes data to file or device
или
_hread Reads from a file
_hwrite Writes to a file
_lclose Closes an open file
_lcreat Creates or opens a file
_llseek Repositions the file pointer
_lopen Opens a file
_lread Reads from a file
_lwrite Writes to a file


 
Elen ©   (2006-05-19 12:47) [2]

После каждой строки добавляй символы скажем chr(13) и записывай, а при загрузке считывай все в память и разбивай на строки по этим символам.


 
Gydvin ©   (2006-05-19 13:43) [3]

procedure TForm1.Button1Click(Sender: TObject);
var
 handl: THandle;
 s: string;
 count1: cardinal;
begin

//save
 handl := 0;
 s := memo1.text;
 count1 := 0;
 handl := CreateFile(PChar("test.txt"), GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
 if not WriteFile(handl, pchar(s)^, Length(s), count1, nil) then showmessage("error");
 closehandle(handl);

end;

procedure TForm1.Button2Click(Sender: TObject);
var
 handl: THandle;
 s: string;
 count1, count2: cardinal;
 t: pointer;
begin
//read
 handl := 0;
 count1 := 0;
 count2 := 0;
 handl := CreateFile(PChar("test.txt"), GENERIC_READ, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
 count2 := GetFileSize(handl, @count2);
 setlength(s, count2);
 ReadFile(handl, pchar(s)^, count2, Count1, nil);
 closehandle(handl);
 memo2.text := s;
end;


если нельзя мемо, то можно использовать след конструкцию

for x:=0 to countСТРОК-1 do
строка:=строка+#13#10+строкаX


 
Creative   (2006-05-19 15:24) [4]

> Gydvin ©

спасибо



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

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

Наверх




Память: 0.47 MB
Время: 0.039 c
2-1148018581
elfebet
2006-05-19 10:03
2006.06.04
Как програмно перевернуть экран?


4-1141572142
Veon
2006-03-05 18:22
2006.06.04
Взаимодействие с Edit


8-1136560269
Syrnik
2006-01-06 18:11
2006.06.04
DShow: Разделить стерео аудио на 2 моно


15-1146905908
Winston [BGMD]
2006-05-06 12:58
2006.06.04
WinSock


2-1147806420
redlord
2006-05-16 23:07
2006.06.04
управление чужим приложением