Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#3

AW: Komponenten ansprechen - mit ini konfigurieren

  Alt 30. Jul 2012, 13:46
Mit RTTI in der Art von:

Delphi-Quellcode:
procedure TVorlage.LoadAndUseRestrinct(const fn:String);
var
  sl:TStringList;
  i:Integer;
  ClassNam,Prop,Info:String;

  Procedure ParseLine(const s:String);
    var
    st:String;
    begin
    st:=s;
    ClassNam:=Copy(st,1,pos(',',st)-1);
    st:=Copy(st,pos(',',st)+1,length(st));
    Prop:=Copy(st,1,pos(',',st)-1);
    Info:=Copy(st,pos(',',st)+1,length(st));
    end;
begin
  sl:=TStringList.Create;
  try
  sl.LoadFromFile(fn);
  for i:=0 to sl.Count - 1 do
    begin
    try
    ParseLine(sl[i]);
    SetProperty(Self,Classnam,Prop,Info);
    except end;
    end;
  finally
  sl.Free;
  end;
end;


Procedure SetProperty(Parent:TComponent;Const ClassNam,Prop:String;Info:Variant);
var
PropInfo: PPropInfo;
Kind:TTypeKind;
begin

if Parent.FindComponent(ClassNam)<>nil then
   begin

   PropInfo := GetPropInfo(Parent.FindComponent(ClassNam),Prop);
   if PropInfo<>nil then
     begin

     Kind:=PropInfo.PropType^.Kind;
     Case Kind of
        tkUnknown:;
        tkInteger:try
                  SetOrdProp(Parent.FindComponent(ClassNam),PropInfo.Name,StrToInt(Info));
                  except
                  SetPropValue(Parent.FindComponent(ClassNam),PropInfo.Name,GetColorForString(Info));
                  end;
        tkChar: SetPropValue(Parent.FindComponent(ClassNam),PropInfo.Name,Info);
        tkEnumeration:SetEnumProp(Parent.FindComponent(ClassNam),PropInfo,Info);
        tkFloat: SetFloatProp(Parent.FindComponent(ClassNam),PropInfo,StrToFloat(Info));
        tkString: SetStrProp(Parent.FindComponent(ClassNam),PropInfo,Info);
        tkSet: SetSetProp(Parent.FindComponent(ClassNam),PropInfo,Info);
        tkClass:;
        tkMethod:;
        tkWChar: SetStrProp(Parent.FindComponent(ClassNam),PropInfo,Info);
        tkLString: SetStrProp(Parent.FindComponent(ClassNam),PropInfo,Info);
        tkWString: SetPropValue(Parent.FindComponent(ClassNam),PropInfo.Name,Info);
        tkVariant: SetVariantProp(Parent.FindComponent(ClassNam),PropInfo,Info);
        tkArray: ;
        tkRecord: ;
        tkInterface:;
        tkInt64: SetInt64Prop(Parent.FindComponent(ClassNam),PropInfo,StrToInt64(Info));
        tkDynArray: ;
     end;
     end;
   end;
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat