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

Вниз

вдогонку о вопросе "как прогнать все переменные"   Найти похожие ветки 

 
syte_ser78 ©   (2006-06-15 17:12) [0]

Замучился уже.
Подозреваю что делаю не правильно, а как правильно, не могу придумать.

Хочу чтобы мое приложение после перезагрузки запускалось в таком же виде в каком я с него вышел. К этому относится:
видимость столбцов дбгрида на нескольких формах
размеры столбцов дбгрида .....
шрифты гриды
колво строк в гридах (DBGridEx)
....
да всего уже не упомнишь.

Пишу все эти значения в ини по закрытию главной формы, по запуску - читаю.
А нельзя ли както попроще? Записать все это гамузом и так же прочесть?


 
Игорь Шевченко ©   (2006-06-15 17:14) [1]

RxLib TFormStorage


 
homm ©   (2006-06-15 17:22) [2]

Stream.WriteComponent
Или что-то подобное


 
Desdechado ©   (2006-06-15 20:44) [3]

> колво строк в гридах (DBGridEx)
тогда уж и копию состояния БД записывай, а то ведь набор данных может поменяться...


 
Marser ©   (2006-06-15 21:10) [4]

Я в TListView ручками делал, в ини-файл сохранял...


 
Жуков Олег   (2006-06-16 00:12) [5]

Есть идея. Обычно свойства, отвечающие за внешний вид у разных элементов одинаково называются и являются published. Поэтому, подключаем TypInfo, и вперёд:

const
 PropertiesToSave: Array[0..5] of string
   = ("Top", "Left", "Width", "Height", "Visible", "Columns");
 ClassesToSave: Array[0..0] of string
   = ("TListView");

procedure SaveComponent(
 const Component: TPersistent;
 const Inifile: TInifile;
 const Section: string
 );
var
 i: Integer;
 PropInfo: PPropInfo;
 ChildComponent: TObject;
 ComponentIndex: Integer;
 Ident: string;
begin

 Ident := Component.GetNamePath;

 for i := Low(PropertiesToSave) to High(PropertiesToSave) do
 begin
   PropInfo := GetPropInfo(Component, PropertiesToSave[i]);
   if PropInfo <> nil then

     case PropInfo^.PropType^.Kind of
       tkClass:
       begin
         ChildComponent := GetObjectProp(Component, PropInfo);
         if ChildComponent <> nil then
           if ChildComponent is TPersistent then
             SaveComponent(ChildComponent as TPersistent,
               Inifile, Section);
       end;
       tkInteger, tkEnumeration:
       begin
         Inifile.WriteInteger(
           Section,
           Ident + "." + PropertiesToSave[i],
           GetOrdProp(Component, PropInfo)
           );
       end;
     end; // case

 end; // for

 if Component is TComponent then
   for ComponentIndex := 0 to TComponent(Component).ComponentCount - 1 do
   begin
     ChildComponent := TComponent(Component).Components[ComponentIndex];
     for i := Low(ClassesToSave) to High(ClassesToSave) do
       if ChildComponent.ClassType.ClassNameIs(ClassesToSave[i]) then
          SaveComponent(ChildComponent as TComponent,
             Inifile, Section);
   end;

 if Component is TCollection then
   for i := 0 to (Component as TCollection).Count - 1 do
   begin
     ChildComponent := (Component as TCollection).Items[i];
     SaveComponent(ChildComponent as TCollectionItem,
         Inifile, Section);
   end;

end;

procedure TForm5.btnSaveClick(Sender: TObject);
var
 Inifile: TIniFile;
begin
 Inifile := TIniFile.Create("c:\test.INI");
 try
   SaveComponent(Self, Inifile, Name);
 finally
   Inifile.Destroy()
 end;
end;

Писал на скорую руку, поэтому возможны ошибки. Это только сохранение, но думаю, что и загрузку по тому же принципу можно сделать.

В результате получается такой Ini файл:
[Form5]
Form5.Top=220
Form5.Left=220
Form5.Width=500
Form5.Height=369
Form5.Visible=1
ListView1.Top=136
ListView1.Left=84
ListView1.Width=305
ListView1.Height=150
ListView1.Visible=1
ListView1.Columns[0].Width=50
ListView1.Columns[1].Width=50
ListView1.Columns[2].Width=50


 
syte_ser78 ©   (2006-06-16 08:59) [6]

Desdechado ©   (15.06.06 20:44) [3]
Ты не понял. Не колво записи в таблицах а количество строк в одной записи многострочного DBGridEx-a



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

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

Наверх




Память: 0.48 MB
Время: 0.026 c
15-1150721661
Crazy monkey
2006-06-19 16:54
2006.07.16
Старая вещчица, но смешеая.


2-1151569501
learner
2006-06-29 12:25
2006.07.16
Управление VCL из нити


4-1144179410
in-tank
2006-04-04 23:36
2006.07.16
Системные параметры процесса


3-1147356242
Boris Marchenko
2006-05-11 18:04
2006.07.16
Ошибка при залогинивании в IBConsole


2-1151262173
Chort
2006-06-25 23:02
2006.07.16
Мастер добавления