Registriert seit: 24. Feb 2007
Ort: Baden
1.566 Beiträge
Delphi 2007 Professional
|
Re: Werte aus einer Form sichern und zurückschreiben
21. Mai 2009, 11:12
Also ich hatte da mal früher einen Weg, den ich heute nicht mehr gehen würde. Aber trifft Deine Aufgabe wohl so in etwa:
Delphi-Quellcode:
function CtrlState_To_Ini(IniFile : TIniFile; Section : String; Form : TForm): Boolean;
var
x : Integer;
begin
Result := FALSE;
if (assigned(Form)) and (assigned(IniFile)) then begin
for x := 1 to Form.ComponentCount do begin
with Form do begin
// TEdit
if Components[x-1].ClassName = 'TEdit' then begin
iniFile.WriteString(Section,Components[x-1].Name,(Form.Components[x-1]as TEdit).text);
// TCheckBox1
end else if Components[x-1].ClassName = 'TCheckBox' then begin
iniFile.WriteBool(Section,Components[x-1].Name,(Form.Components[x-1]as TCheckBox).Checked);
// TRadioButtion
end else if Components[x-1].ClassName = 'TRadioButton' then begin
iniFile.WriteBool(Section,Components[x-1].Name,(Form.Components[x-1]as TRadioButton).Checked);
// TRadioGroup
end else if Components[x-1].ClassName = 'TRadioGroup' then begin
iniFile.WriteInteger(Section,Components[x-1].Name,(Form.Components[x-1]as TRadioGroup).ItemIndex);
// TTrackBar
end else if Components[x-1].ClassName = 'TTrackBar' then begin
iniFile.WriteInteger(Section,Components[x-1].Name,(Form.Components[x-1]as TTrackBar).Position);
// THotKey
end else if Components[x-1].ClassName = 'THotKey' then begin
iniFile.WriteInteger(Section,Components[x-1].Name,(Form.Components[x-1]as THotKey).HotKey);
// TSpinEdit
end else if Components[x-1].ClassName = 'TSpinEdit' then begin
iniFile.WriteInteger(Section,Components[x-1].Name,(Form.Components[x-1]as TSpinEdit).Value);
// TComboBox
end else if Components[x-1].ClassName = 'TComboBox' then begin
iniFile.WriteInteger(Section,Components[x-1].Name,(Form.Components[x-1]as TComboBox).ItemIndex);
end;
end;
end;
Result := TRUE;
end;
end;
function Ini_To_CtrlState(IniFile : TIniFile; Section : String; Form : TForm): Boolean;
var
x : Integer;
TempComponent : TComponent;
sl : TStringList;
begin
Result := FALSE;
if (assigned(Form)) and (assigned(IniFile)) then begin
// Alle Item-Namen einlesen
sl := TStringList.Create;
try
iniFile.ReadSection(Section,sl);
for x := 1 to sl.Count do begin
TempComponent := Form.FindComponent(sl[x-1]);
if assigned(TempComponent) then begin
// TEdit
if TempComponent.ClassName = 'TEdit' then begin
TEdit(TempComponent).Text := IniFile.ReadString(Section,TempComponent.Name,'');
// TCheckBox
end else if TempComponent.ClassName = 'TCheckBox' then begin
TCheckBox(TempComponent).Checked := IniFile.ReadBool(Section,TempComponent.Name,FALSE);
// TRadioButtion
end else if TempComponent.ClassName = 'TRadioButton' then begin
TRadioButton(TempComponent).Checked := IniFile.ReadBool(Section,TempComponent.Name,FALSE);
// TRadioGroup
end else if TempComponent.ClassName = 'TRadioGroup' then begin
TRadioGroup(TempComponent).ItemIndex := IniFile.ReadInteger(Section,TempComponent.Name,0);
// TTrackBar
end else if TempComponent.ClassName = 'TTrackBar' then begin
TTrackBar(TempComponent).Position := IniFile.ReadInteger(Section,TempComponent.Name,0);
// THotKey (Hier Eigenwert als Default)
end else if TempComponent.ClassName = 'THotKey' then begin
THotKey(TempComponent).HotKey := IniFile.ReadInteger(Section,TempComponent.Name,THotKey(TempComponent).HotKey);
// TSpinEdit
end else if TempComponent.ClassName = 'TSpinEdit' then begin
TSpinEdit(TempComponent).Value := IniFile.ReadInteger(Section,TempComponent.Name,TSpinEdit(TempComponent).Value);
// TComboBox
end else if TempComponent.ClassName = 'TComboBox' then begin
TComboBox(TempComponent).ItemIndex := IniFile.ReadInteger(Section,TempComponent.Name,TComboBox(TempComponent).ItemIndex);
end;
end;
end;
finally
sl.Free;
end;
Result := TRUE;
end;
end;
|
|
Zitat
|