Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  119

•  TDictionary Custom Sort  3 307

•  Fast Watermark Sources  3 057

•  3D Designer  4 811

•  Sik Screen Capture  3 308

•  Patch Maker  3 524

•  Айболит (remote control)  3 625

•  ListBox Drag & Drop  2 986

•  Доска для игры Реверси  81 505

•  Графические эффекты  3 914

•  Рисование по маске  3 221

•  Перетаскивание изображений  2 604

•  Canvas Drawing  2 727

•  Рисование Луны  2 550

•  Поворот изображения  2 159

•  Рисование стержней  2 158

•  Paint on Shape  1 562

•  Генератор кроссвордов  2 221

•  Головоломка Paletto  1 762

•  Теорема Монжа об окружностях  2 207

•  Пазл Numbrix  1 679

•  Заборы и коммивояжеры  2 050

•  Игра HIP  1 275

•  Игра Go (Го)  1 221

•  Симулятор лифта  1 468

•  Программа укладки плитки  1 212

•  Генератор лабиринта  1 539

•  Проверка числового ввода  1 347

•  HEX View  1 486

•  Физический маятник  1 352

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Сохранить несколько потоков в сжатый зашифрованный файл



Оформил: DeeCo

{ 
 This example shows you how to save many streams into a single file and load it again. 
 You need to install the HKStream component from the Demo-Download. 
 The HKStreams component enables you to store streams with LHA compression if wanted, 
 and can also be  encrypted with blowfish. 
 THKStreams is also smart, if you load afterwards an encrypted or compressed (or both) file, 
 it will now how to read it, and can also call your event that asks the user 
 for a password if needed. 

 In the following example we will store several components 
 (TMemo, TListbox, some other controls) 
 and a Version-Information in a single file and then read it back. 

 THKStreams enables you to write your own file format and easily access streams 
 in a file, as they are stored in different sections. 
}

 { 
 Dieses Beispiel zeigt, wie man mehrere Stream in eine Datei speichern kann. 
 Dafur wird die THKStreams Komponente verwendet, welche es unter anderem erlaubt, 
 eine Datei mit LHA zu komprimieren und mit Blowfish zu verschlussseln. 
 Auch kann einer Datei ein Passwort hinzugefugt werden, welches dann beim Offnen 
 der Datei vom Benutzer eingegeben werden muss. 

 Im Beispiel werden einige Komponenten wie TMemo, TListbox und diverse Controls einer 
 Groupbox und Versions-Informationen in einer einzigen Datei gespeichert. 

 Mit der THKStreams Komponente kann man leicht sein eigenes Dateiformat schreiben und 
 sehr einfach auf Streams zugreifen, da diese in einzelne Sektionen unterteilt sind. 
}

 uses
   HKStreamCol; { from Demo-Download }

 private
     { Private declarations }
     function SaveHKFile(FileName: TFileName): boolean;
     function LoadHKFile(FileName: TFileName): boolean;
   public
     { Public declarations }
   end;

 implementation

 {$R *.dfm}

 //-------------------------------------------------------- 
// Save our File 
function TfrmMain.SaveHKFile(FileName: TFileName): Boolean;
 //-------------------------------------------------------- 
var
   ms: TMemoryStream;
   i: integer;
   s: string;
   StrList: TStringList;
 begin
   ms := TMemoryStream.Create;
   try
     with HKStreams1 do
     begin
       // Version Info 
      //-------------------------------- 
      i := 1;
       ms.Write(I, SizeOf(I));
       AddStream('Version-Info', ms);
       ms.Clear;
       // Author Info 
      //-------------------------------- 
      s := 'Your Name';
       ms.WriteBuffer(s[1], Length(s));
       AddStream('Author-Info', ms);
       ms.Clear;
       // Memo1 
      //-------------------------------- 
      Memo1.Lines.SaveToStream(ms);
       AddStream('Memo1', ms);
       ms.Clear;
       // ListBox1 
      //------------------------------- 
      ListBox1.Items.SaveToStream(ms);
       AddStream('ListBox1', ms);
       ms.Clear;
       // Different Controls on Groupbox1 
      //------------------------------- 
      // Look at the Demo for GetSettings implementation 
      StrList := TStringList.Create;
       try
         GetSettings(StrList, GroupBox1);
         StrList.SaveToStream(ms);
       finally
         StrList.Free;
       end;
       AddStream('Settings', ms);
       ms.Clear;
       // Save everything 
      // ----------------------------- 
      SaveToFile(FileName);
       ClearStreams;
     end; {with}
   finally
     ms.Free;
   end;
 end;

 //-------------------------------------------------------- 
// Load our File 
function TfrmMain.LoadHKFile(FileName: TFileName): Boolean;
 //-------------------------------------------------------- 
var
   ms: TMemoryStream;
   i: Integer;
   s: string;
   StrList: TStringList;
 begin
   if not FileExists(FileName) then
   begin
     ShowMessage('File not found');
     // Customize Error handling... 
    Exit;
   end;
   try
     HKStreams1.LoadFromFile(FileName);
   except
     on ECorruptFile do Exit;
     on EStreamError do Exit;
   end;
   ms := TMemoryStream.Create;
   try
     with HKStreams1 do
     begin
       // Version Info 
      //-------------------------------- 
      GetStream('Version-Info', ms);
       ms.read(i, SizeOf(i));
       label1.Caption := 'Version: ' + IntToStr(i);
       ms.Clear;
       // Author Info 
      //-------------------------------- 
      GetStream('Author-Info', ms);
       SetLength(S, ms.Size);
       ms.read(S[1], ms.Size);
       Label2.Caption := 'Author: ' + s;
       ms.Clear;
       // Memo1 
      //-------------------------------- 
      GetStream('Memo1', ms);
       Memo1.Lines.LoadFromStream(ms);
       ms.Clear;
       // ListBox1 
      //------------------------------- 
      GetStream('ListBox1', ms);
       ListBox1.Items.LoadFromStream(ms);
       ms.Clear;
       // Different Controls on Groupbox1 
      //------------------------------- 
      // Look at the Demo for SetSettings implementation 
      GetStream('Settings', ms);
       StrList := TStringList.Create;
       try
         StrList.LoadFromStream(ms);
         SetSettings(StrList);
       finally
         StrList.Free;
       end;
       { ----------------------------- }
       ClearStreams;
     end; {with}
   finally
     ms.Free;
   end;
 end;

 //-------------------------------------------------------- 
// Save Dialog 
procedure TfrmMain.btnSaveClick(Sender: TObject);
 //-------------------------------------------------------- 
begin
   if SaveDialog1.Execute then
   begin
     SaveHKFile(SaveDialog1.FileName);
   end;
   // Clear controls 
  ListBox1.Clear;
   Memo1.Clear;
   Edit1.Clear;
   Edit2.Clear;
   Edit3.Clear;
   Edit4.Clear;
   CheckBox1.Checked := not CheckBox1.Checked;
   CheckBox2.Checked := not CheckBox2.Checked;
 end;

 //-------------------------------------------------------- 
// Open Dialog 
procedure TfrmMain.btnLoadClick(Sender: TObject);
 //-------------------------------------------------------- 
begin
   if OpenDialog1.Execute then
   begin
     LoadHKFile(OpenDialog1.FileName);
   end;
 end;




Похожие по теме исходники

Чтение PSD файлов

Шифратор файлов

Разбиение файла на части

Поиск файлов

 

FileMan (менеджер файлов)

Поиск открытых файлов

Текст внутри файла




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте