Witam
Mam pytanie, macie jakieś sprawdzone (szybkie) sposoby na częściową możliwość dostosowania formatek do specyficznych potrzeb klienta ? Chodzi mi przede wszystkim o to żeby można to było zrobić, bez przeróbek programu. Nie chodzi mi o to żeby użytkownik musiał/mógł w tym grzebać, tylko np handlowiec który "może sobie popaprać ręce grzebiąc np w plikach ini" dostosowuje formatke pod klienta. Przede wszystkim chodzi o labelki, kolumny, hinty, widoczność pewnych rzeczy.
Na razie mam taki pomysł żeby zapisywać właściwości komponentów formatki do ini i potem je wczytywać, ale działa to troche wolno.
procedure OdczytajKontrolki(aForm: TForm);
var i : Integer;
Ini: TIniFile;
K : TComponent;
begin
Ini := TIniFile.Create('test.ini');
try
For i := 0 to aForm.ComponentCount - 1 do
Begin
K := aForm.Components[i];
If (Ini.ReadString(K.Name,'ClassName', '') = K.ClassName)then
Begin
If HasProp(K, 'Left') then
Begin
SetProp(K, 'Left', Ini.ReadInteger(K.Name, 'Left', GetPropInteger(K, 'Left')));
SetProp(K, 'Top', Ini.ReadInteger(K.Name, 'Top', GetPropInteger(K, 'Top')));
SetProp(K, 'Width', Ini.ReadInteger(K.Name, 'Width', GetPropInteger(K, 'Width')));
SetProp(K, 'Height', Ini.ReadInteger(K.Name, 'Height', GetPropInteger(K, 'Height')));
End;
If HasProp(K, 'Visible') then
SetProp(K, 'Visible', Ini.ReadBool(K.Name, 'Visible', GetPropBool(K, 'Visible')));
If HasProp(K, 'TabVisible') then
SetProp(K, 'TabVisible', Ini.ReadBool(K.Name, 'TabVisible', GetPropBool(K, 'TabVisible')));
If HasProp(K, 'Hint') then
SetProp(K, 'Hint', Ini.ReadString(K.Name, 'Hint', GetPropString(K, 'Hint')));
If HasProp(K, 'Caption') then
SetProp(K, 'Caption', Ini.ReadString(K.Name, 'Caption', GetPropString(K, 'Caption')));
If HasProp(K, 'TabOrder') then
SetProp(K, 'TabOrder', Ini.ReadInteger(K.Name, 'TabOrder', GetPropInteger(K, 'TabOrder')));
//..
End;
End;
finally
FreeAndNil(Ini);
end;
End;
procedure ZapiszKontrolki(aForm: TForm);
var i : Integer;
Ini: TIniFile;
K : TComponent;
begin
Ini := TIniFile.Create('test.ini');
try
For i := 0 to aForm.ComponentCount - 1 do
Begin K := aForm.Components[i];
Ini.WriteString(K.Name, 'ClassName', K.ClassName);
If HasProp(K, 'Caption') then
Ini.WriteString (K.Name, 'Caption', GetPropString(K, 'Caption'));
If HasProp(K, 'Left') then
Begin
Ini.WriteInteger(K.Name, 'Left', GetPropInteger(K, 'Left'));
Ini.WriteInteger(K.Name, 'Top', GetPropInteger(K, 'Top'));
Ini.WriteInteger(K.Name, 'Width', GetPropInteger(K, 'Width'));
Ini.WriteInteger(K.Name, 'Height', GetPropInteger(K, 'Height'));
End;
If HasProp(K, 'Visible') then
Ini.WriteBool(K.Name, 'Visible', GetPropBool(K, 'Visible'));
If HasProp(K, 'TabVisible') then
Ini.WriteBool(K.Name, 'TabVisible', GetPropBool(K, 'TabVisible'));
If HasProp(K, 'Hint') then
Ini.WriteString (K.Name, 'Hint', GetPropString(K, 'Hint'));
If HasProp(K, 'TabOrder') then
Ini.WriteInteger(K.Name, 'TabOrder', GetPropInteger(K, 'TabOrder'));
End;
finally
FreeAndNil(Ini);
end;
End;
function HasProp(aComponent: TComponent; aProp: String): Boolean;
var thePropInfo : PPropInfo;
begin
thePropInfo := nil;
thePropInfo := GetPropInfo(aComponent.ClassInfo, aProp);
Result := (thePropInfo <> nil);
end;
procedure SetProp(aComponent: TComponent; aProp: String; aValue: Integer); overload;
var thePropInfo: PPropInfo;
begin
thePropInfo := nil;
thePropInfo := GetPropInfo(aComponent.ClassInfo, aProp); If thePropInfo <> nil then
If thePropInfo^.PropType^.Kind = tkInteger then SetOrdProp(aComponent, thePropInfo, aValue);
end;
function GetPropString(aComponent: TComponent; aProp: String) : String;
var thePropInfo: PPropInfo;
begin
thePropInfo := nil;
thePropInfo := GetPropInfo(aComponent.ClassInfo, aProp);
If thePropInfo <> nil then
If thePropInfo^.PropType^.Kind in [tkString, tkChar, tkWChar, tkLString, tkWString] then
Result := GetStrProp(aComponent, aProp);
end;
// dalej inne metody z serii setprop, getprop napisane przez analogię
Chciałbym obejść się bez rzutowania, bo w projekcie zastosowano dużo komponentów z różnych źródeł.Macie jakieś pomysły na taki mechanizm, lub jak przyśpieszyć ten co podałem ?Pisząc że działa wolno mam na myśli jakieś 2.5 sek przy odczycie 700 komponentów, 3.5 przy zapisie.Podejrzewam że wolne działanie to wina RTTI, jakbym rzutował to może by to działało szybciej.
P.S. sorry za brak wcięć w kodzie ale przy publikowaniu posta, wyleciał jakiś błąd i wyszło jak wyszło.
A może sprawdzić czy jak np nie ma właściwości Visible to komponent pominąć - wyeliminowało by to sprawdzanie właściwości dla komponentów niewizualnych.
Niewizualnych jest ok. 20 - więc "dopał" jest niewielki : )