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

•  TDictionary Custom Sort  3 226

•  Fast Watermark Sources  2 992

•  3D Designer  4 751

•  Sik Screen Capture  3 259

•  Patch Maker  3 467

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

•  ListBox Drag & Drop  2 904

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

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

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

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

•  Canvas Drawing  2 672

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

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

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

•  Paint on Shape  1 525

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

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

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

•  Пазл Numbrix  1 649

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

•  Игра HIP  1 262

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

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

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

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

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

•  HEX View  1 466

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

•  Задача коммивояжера  1 357

 
скрыть


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

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



Delphi Sources

Автоматическое сохранение или загрузка установок пользователя



Оформил: DeeCo

private
   procedure SaveConfig(fn: string);
   procedure LoadConfig(fn: string);
 end;

 implementation

 {....}

 procedure TForm1.SaveConfig(fn: string);   // fn: Filename where to save the stream 
{ 
 Saves all TWinControl-descendants of all Pages of a PageControl in a stream 
 can easy be used to save userdefined Options 
 Place a new control to the PageControl and it will be saved to the stream, without 
 any additional codeline 

 Speichert alle Abkommlinge von TWinControl auf allen Seiten eines PageControls 
 in ein File 
 Erleichtert das Speichern von benutzerdefinierten Optionen 
 Einfach ein neues Control auf das PageControl setzen und es wird ohne zusatzlichen 
 Code gespeichert 
}
     var
       Stream: TFileStream;
       i, j: Integer;
       ObjName: string[255];
     begin
       Stream := TFileStream.Create(fn, fmCreate);
       try
         Stream.Position := 0;
         // Walk throug every Control on every Page of a PageControl 
        // Alle Controls auf allen Pages eines PageControls durchlaufen 
        for j := 0 to PageControl.PageCount - 1 do
         begin
           for i := 0 to PageControl.Pages[j].ControlCount - 1 do
           begin
             if PageControl.Pages[j].Controls[i] is TWinControl then
             begin
               // If the control is a descendant of TWinControl, then save it in the 
              // stream incl. name and length 
              // Wenn das Control von TWinControl abstammt, dann mit Namen und Lange 
              // in den Stream speichern 
              ObjName := PageControl.Pages[j].Controls[i].Name;
               Stream.WriteBuffer(ObjName, Length(ObjName) + 1);
               Stream.WriteComponent(PageControl.Pages[j].Controls[i]);
             end;
           end;
         end;
       finally
         Stream.Free;
       end;
     end;

     procedure TForm1.LoadConfig(fn: string);  // fn: Filename from where to load the stream 
      // Loads the controls back from the stream 
      // Ladt aus dem gespeicherten Stream den Zustand der Controls zuruck 
    var
        Stream: TFileStream;
       ObjName: string[255];
       ObjNameLen: Byte;
       i, j: Integer;
     begin
       Stream := TFileStream.Create(fn, fmOpenRead or fmShareDenyNone);
       try
         Stream.Position := 0;
         // walk through the stream 
        // durch den ganzen Stream gehen 
        while Stream.Position do
         begin
           try
             // get objectname 
            // Objektname holen 
            Stream.Read(ObjName[0], 1);
             ObjNameLen := Byte(ObjName[0]);
             Stream.Read(ObjName[1], ObjNameLen);
           finally
           end;
           // Search the control on the PageControl 
          // Das Control auf dem PageControl suchen 
          for j := 0 to PageControl.PageCount - 1 do
           begin
             for i := 0 to PageControl.Pages[j].ControlCount - 1 do
             begin
               if PageControl.Pages[j].Controls[i] is TWinControl then
               begin
                 if ObjName = PageControl.Pages[j].Controls[i].Name then
                 begin
                   try
                     if PageControl.Pages[j].Controls[i] is TCheckbox then
                       // TCheckbox has to be set to False 
                      // TCheckbox muss zuerst auf False gesetzt werden 
                      (PageControl.Pages[j].Controls[i] as TCheckbox).Checked := False;
                     // load control 
                    // Control laden 
                    Stream.ReadComponent(PageControl.Pages[j].Controls[i]);
                   finally
                   end;
                 end;
               end;
             end;
           end;
         end;
       finally
         Stream.Free;
       end;
     end;


     { Save}
     procedure TForm1.Button2Click(Sender: TObject);
     begin
       SaveConfig('pagecontrol.dat');
     end;

     { Load}
     procedure TForm1.Button1Click(Sender: TObject);
     begin
       LoadConfig('pagecontrol.dat');
     end;







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

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