Hi all.
My preference has always been INI files over registry entries. Here is a very useful
component.
Unfortunately, it cant save checklistbox information.
I tried unsuccessfully to save these items by using a GetPropInfo search value of
'Items'
which brings up the component, but not the internal values eg Checklistbox1.checked[0].
Cant seem to work my way through this one, anyone got any ideas?
Here is what I have been playing with:
var prop: PPropInfo;
Tstring:string;
prop := GetPropInfo(Owner.Components[i].ClassInfo, 'Items'); //Get all Strings
Items
Tstring:= lowercase(Owner.Components[i].ClassName); //Get the base
class name
if (prop <> nil) and (pos('checklistbox',Tstring)>0) then //Ascertain its a
checklistbox
Then here is the problem area:
with Owner.Components[i].Name as Tchecklistbox do //Throws a compile error
begin
J:= Items.Count-1;
Due to the component not knowing about the Owner, it may not be possible?
Then I would iterate through the checked items, and save the INI, which would be used
in below:
> INIVAL : Save and Load fields values from INI file.
>
> This small component when placed in a form Save and Load automatically the
> properties Text, Value and Checked of every the components of the form.
> I use it for remember configuration items.
If you want the source give me a yell.
procedure TIniVal.Save;
var ini: TIniFile;
prop : PPropInfo;
i: Integer;
begin
ini := TIniFile.Create(GetName);
try
for i := 0 to Owner.ComponentCount -1 do begin
prop := GetPropInfo(Owner.Components[i].ClassInfo, 'Text');
if (prop <> nil) and (prop^.PropType^.Kind in [tkString,tkLString,tkWString])
then
ini.WriteString(Owner.Name,Owner.Components[i].Name,GetStrProp(Owner.Components[i],
prop));
prop := GetPropInfo(Owner.Components[i].ClassInfo, 'Value');
if (prop <> nil) and (prop^.PropType^.Kind in [tkString,tkLString,tkWString])
then
ini.WriteString(Owner.Name,Owner.Components[i].Name,GetStrProp(Owner.Components[i],
prop));
if (prop <> nil) and (prop^.PropType^.Kind = tkInteger) then
ini.WriteInteger(Owner.Name,Owner.Components[i].Name,GetOrdProp(Owner.Components[i],
prop));
prop := GetPropInfo(Owner.Components[i].ClassInfo, 'Checked');
if (prop <> nil) then
ini.WriteBool(Owner.Name,Owner.Components[i].Name,Boolean(GetOrdProp(Owner.Components[i],
prop)));
end;
finally
ini.Free;
end;
end;
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi