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

Вниз

Работа с INI файлами   Найти похожие ветки 

 
s ©   (2004-04-12 13:31) [0]

Добрый день!
Подскажите, пожалуйста, как правильно работать с ini-файлами.
Задача:
Есть дочернее окно (fsMDIChild). В ini-файле находится описание компонентов, которые должны быть в окне.

Ini-файл формирую следующим образом (в общем виде):
[Project]
MDIChild
Label1
Edit1
CheckBox1
...
[MDIChild]
Height=..
Width=..
..
[Label1]
Left=..
Height=..
Top=..
Width=..
..

Как можно программно выполнить создание компонента и задать его свойства по данным ini-файла?

Спасибо


 
Ega23 ©   (2004-04-12 13:52) [1]

Вот пример небольшой:

[Info]
SectionCount=11

[VarTyps]
Integer=1
String=2
Font=3

[ObjectTyps]
Text=0
Picture=1
Photo=2
Common=3

[ComponentTyps]
ComponentTypsCount=4
TEdit=1
TComboBox=2
TCheckBox=3
FontButton=4

[Section1]
Nam=Common
Caption=Общие
ObjectType=3
KeysCount=7
;Key1
Key1Nam=BgrFrontFile
Key1VarTyp=2
Key1ComponentTyp=1
Key1ItemCount=0
Key1Caption=Лицевой фон
Key1Default=tpl\ct1.bmp
Key1DefaultTyp=2
;Key2
Key2Nam=BgrBackFile
Key2VarTyp=2
Key2ComponentTyp=1
Key2Default=tpl\ct1_rev.bmp
Key2DefaultTyp=2
Key2Caption=Задний фон
Key2ItemCount=0
;Key3
Key3Nam=TransparentColor
Key3VarTyp=1
Key3ComponentTyp=1
Key3Caption=Прозрачный цвет
Key3ItemCount=0
Key3Default=16777215
Key3DefaultTyp=1
;Key4
Key4Nam=Orientation
Key4VarTyp=1
Key4ComponentTyp=2
Key4Caption=Ориентация
Key4ItemCount=2
Key4Item1=Книжная
Key4Item2=Альбомная
Key4Default=0
Key4DefaultTyp=1
;Key5
Key5Nam=HasReverse
Key5VarTyp=1
Key5ComponentTyp=2
Key5Caption=Вид пропуска
Key5ItemCount=3
Key5Item1=Только лицевая
Key5Item2=Лицевая и фон на обратной
Key5Item3=Лицевая и обратная
Key5Default=0
Key5DefaultTyp=1
;Key6
Key6Nam=Version
Key6VarTyp=1
Key6ComponentTyp=0
Key6ItemCount=0
Key6Default=3
Key6DefaultTyp=1
;Key7
Key7Nam=AnyTextCount
Key7VarTyp=1
Key7ComponentTyp=0
Key7ItemCount=0
Key7Default=0
Key7DefaultTyp=1

[Section2]
Nam=Photo
Caption=Фотография
ObjectType=2
KeysCount=5
;Key1
Key1Nam=Left
Key1VarTyp=1
Key1ComponentTyp=1
Key1Caption=Х коорд.
Key1ItemCount=0
Key1Default=0
Key1DefaultTyp=1
;Key2
Key2Nam=Top
Key2VarTyp=1
Key2ComponentTyp=1
Key2Caption=Y коорд.
Key2ItemCount=0
Key2Default=0
Key2DefaultTyp=1
;Key3
Key3Nam=Width
Key3VarTyp=1
Key3ComponentTyp=1
Key3Caption=Ширина
Key3ItemCount=0
Key3Default=0
Key3DefaultTyp=1
;Key4
Key4Nam=Height
Key4VarTyp=1
Key4ComponentTyp=1
Key4Caption=Высота
Key4ItemCount=0
Key4Default=0
Key4DefaultTyp=1
;Key5
Key5Nam=Visible
Key5VarTyp=1
Key5ComponentTyp=3
Key5Caption=Виден
Key5ItemCount=0
Key5Default=0
Key5DefaultTyp=1

[Section3]
Nam=PersNam1
Caption=Фамилия
ObjectType=0
KeysCount=4
;Key1
Key1Nam=Left
Key1VarTyp=1
Key1ComponentTyp=1
Key1Caption=Х коорд.
Key1ItemCount=0
Key1Default=0
Key1DefaultTyp=1
;Key2
Key2Nam=Top
Key2VarTyp=1
Key2ComponentTyp=1
Key2Caption=Y коорд.
Key2ItemCount=0
Key2Default=0
Key2DefaultTyp=1
;Key3
Key3Nam=FontAttr
Key3VarTyp=3
Key3ComponentTyp=4
Key3Caption=Параметры шрифта
Key3ItemCount=0
Key3DefaultTyp=3
Key3DefaultFontNam=Arial
Key3DefaultFontSize=48
Key3DefaultFontStyle=0
Key3DefaultFontColor=0
;Key4
Key4Nam=Visible
Key4VarTyp=1
Key4ComponentTyp=3
Key4Caption=Виден
Key4ItemCount=0
Key4Default=0
Key4DefaultTyp=1

И так далее ...


 
s ©   (2004-04-12 14:05) [2]

Это пример ini-файла. А как правильно использовать его в теле программы?
Как можно программно выполнить создание компонента и задать его свойства по данным ini-файла?


 
default ©   (2004-04-12 14:06) [3]

s ©   (12.04.04 14:05) [2]
см. класс TIniFile


 
serge35   (2004-04-12 14:13) [4]

> Как можно программно выполнить создание компонента
Create.
и далее присвоение всех свойств.


 
Ega23 ©   (2004-04-12 14:20) [5]

На примере моего файла:
Есть 4 основные секции, в первой - счтчик секций, вторая - типы данных, третья - типы объектов и т.п.
Читаешь кол-во секций, дальше в цикле -
"Section"+IntToStr(SectionCount) - количество ключей в данной секции и т.п.
Пример:

procedure TTPLObjectsIni.ReadMainIni;
var
ss,SectionStr:String;
i,j,k, SectionCount, KeyCount, KeyItemCount:Integer;
Section:TSectionObject;
Key:TKeyObject;
begin
SectionCount:=MainIniFile.ReadInteger("Info","SectionCount",0);

for i:=1 to SectionCount do
 begin
  SectionStr:="Section"+IntToStr(i);
  Section:=AddSection;
  Section.SectionName:=MainIniFile.ReadString(SectionStr,"Nam","");
  Section.SectionCaption:=MainIniFile.ReadString(SectionStr,"Caption","");
  Section.SectionObjectType:=Section.ValueToObjType(MainIniFile.ReadInteger(SectionStr,"ObjectType",-1));
  KeyCount:=MainIniFile.ReadInteger(SectionStr,"KeysCount",0);

  for j:=1 to KeyCount do
   begin
    Key:=Section.AddKey;
    Key.KeyName:=MainIniFile.ReadString(SectionStr,"Key"+IntToStr(j)+"Nam","");
    Key.KeyVarType:=ValueToVarType(MainIniFile.ReadInteger(
                    SectionStr,"Key"+IntToStr(j)+"VarTyp",0));
    Key.KeyComponentType:=ValueToComponentType(MainIniFile.ReadInteger(
                          SectionStr,"Key"+IntToStr(j)+"ComponentTyp",0));
    KeyItemCount:=MainIniFile.ReadInteger(SectionStr,"Key"+IntToStr(j)+"ItemCount",0);
    for k:=1 to KeyItemCount do
      Key.Items.Add(MainIniFile.ReadString(SectionStr,"Key"+IntToStr(j)+
                                           "Item"+IntToStr(k),""));
    Key.KeyCaption:=MainIniFile.ReadString(SectionStr,"Key"+IntToStr(j)+"Caption","");
    Key.KeyDefaultVarType:=ValueToVarType(MainIniFile.ReadInteger(SectionStr,
                                          "Key"+IntToStr(j)+"DefaultTyp",0));
    Case Key.KeyDefaultVarType of
     vtInteger : Key.KeyDefaultInt:=MainIniFile.ReadInteger(SectionStr,
                                    "Key"+IntToStr(j)+"Default",0);
     vtString  : Key.KeyDefaultStr:=MainIniFile.ReadString(SectionStr,
                                    "Key"+IntToStr(j)+"Default","");
     vtFont    : begin
                  Key.KeyFont.FontNam:=MainIniFile.ReadString(SectionStr,
                                       "Key"+IntToStr(j)+"DefaultFontNam","Arial");
                  Key.KeyFont.FontSize:=MainIniFile.ReadInteger(SectionStr,
                                        "Key"+IntToStr(j)+"DefaultFontSize",0);
                  Key.KeyFont.FontColor:=MainIniFile.ReadInteger(SectionStr,
                                         "Key"+IntToStr(j)+"DefaultFontColor",0);
                  Key.KeyFont.FontStyle:=MainIniFile.ReadInteger(SectionStr,
                                         "Key"+IntToStr(j)+"DefaultFontStyle",0);
                 end;
    end; // Case
   end; // for j:=1 to KeyCount do
 end; // for i:=1 to SectionCount do

end;


 
s ©   (2004-04-12 14:48) [6]

Спасибо


 
s ©   (2004-04-12 19:39) [7]

To Ega23:
классы TSectionObject и TKeyObject к какому модулю относятся?


 
Ega23 ©   (2004-04-13 09:26) [8]

классы TSectionObject и TKeyObject к какому модулю относятся?

Это мои собственные классы. Если надо - могу поделится.


 
s ©   (2004-04-13 16:24) [9]

Буду рад ознакомиться с ними


 
Ega23 ©   (2004-04-13 17:13) [10]

TKeyObject=class(TObject)
 private
  FKeyNam: String;
  FKeyCaption : String;
  FKeyComponentType: TComponentType;
  FItems: TStringList;
  FKeyVarType: TVariableType;
  FKeyDefaultInt: Integer;
  FKeyDefaultStr: String;
  FKeyDefaultVarType: TVariableType;
  procedure SetFKeyComponentType(const Value: TComponentType);
  procedure SetFKeyNam(const Value: String);
  procedure SetItems(const Value: TStringList);
 public
  Data:Pointer;
  KeyFont: TFontParams;
  constructor Create(Index:Integer);
  destructor Destroy; override;
  property KeyName:String Read FKeyNam Write SetFKeyNam;
  property Items:TStringList Read FItems write SetItems;
  property KeyComponentType:TComponentType Read FKeyComponentType Write SetFKeyComponentType;
  property KeyVarType:TVariableType Read FKeyVarType Write FKeyVarType;
  property KeyCaption:String Read FKeyCaption Write FKeyCaption;
  property KeyDefaultInt:Integer Read FKeyDefaultInt Write FKeyDefaultInt;
  property KeyDefaultStr:String Read FKeyDefaultStr Write FKeyDefaultStr;
  property KeyDefaultVarType:TVariableType Read FKeyDefaultVarType Write FKeyDefaultVarType;
end;

TSectionObject=class(TObject)
 private
  KeyList:TList;
  FSectionName: String;
  FSectionCaption: String;
  FSectionObjectType: TObjectType;
  FSectionObjectIndex: Integer;

  function GetKeyByIndex(Index: Integer): TKeyObject;
  function GetKeyCount: Integer;
  function ValueToObjType(const Value:Integer):TObjectType;
  function ObjTypeValue(const Value:TObjectType):Integer;
 public
  CommonSection:TCommonSection;
  PhotoSection:TPhotoSection;
  TextSection:TTextSection;
  PictureSection:TPictureSection;
  Data:Pointer;
  constructor Create(Index:Integer);
  destructor Destroy; override;
  function AddKey:TKeyObject;
  function KeyByName(KeyName:String):TKeyObject;
  function GetSectionValues:TObject;
  property Key[Index:Integer]:TKeyObject Read GetKeyByIndex;
  property SectionName:String Read FSectionName Write FSectionName;
  property SectionCaption:String Read FSectionCaption Write FSectionCaption;
  property SectionObjectType:TObjectType Read FSectionObjectType Write FSectionObjectType;
  property SectionObjectIndex:Integer Read FSectionObjectIndex Write FSectionObjectIndex;
  property KeyCount:Integer Read GetKeyCount;
end;


 
s ©   (2004-04-13 19:54) [11]

Спасибо


 
s ©   (2004-04-13 19:59) [12]

Спасибо



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

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

Наверх




Память: 0.51 MB
Время: 0.06 c
7-1078890606
Mike03
2004-03-10 06:50
2004.05.02
многокнопочная мышь


3-1080835043
White
2004-04-01 19:57
2004.05.02
Как узнать кол-во записей в запросе програмно?


3-1081214753
makz
2004-04-06 05:25
2004.05.02
combobox и dataset


1-1081949165
alsov
2004-04-14 17:26
2004.05.02
програмный скролинг в гриде


4-1078409381
Kreon
2004-03-04 17:09
2004.05.02
ScaleViewportExtEx, логические единицы - как их изменять?