Registriert seit: 29. Mai 2002
Ort: Frankfurt
8.252 Beiträge
Delphi 2006 Professional
|
Re: Positionen mehrerer TImage speichern
30. Mär 2006, 19:13
Zitat von smart:
...Ist, glaube ich auch nicht viel mehr Aufwand, oder? ...
Der Vorteil ist: Dich brauchen die Namen der Images nicht zu interessieren
Delphi-Quellcode:
uses
IniFiles;
var
myIniFile : string; // natürlich als private Variable.
procedure SaveImagePos(aForm: TForm; aFileName : string);
var
ndx: Integer;
PositionIni: TMemIniFile;
CurrentCompo: TComponent;
begin
PositionIni := TMemIniFile.Create(aFileName);
try
for ndx := 0 to Pred(aForm.ComponentCount) do
begin
CurrentCompo := aForm.Components[ndx];
if (CurrentCompo is TImage) then
begin
with (CurrentCompo as TImage) do
begin
PositionIni.WriteInteger(Name, 'Top', Top);
PositionIni.WriteInteger(Name, 'Width', Width);
end;
end;
end;
PositionIni.UpdateFile;
finally
PositionIni.free;
end;
end;
procedure LoadImagePos(aForm: TForm; aFileName : string);
var
ndx: Integer;
PositionIni: TMemIniFile;
CurrentCompo: TComponent;
begin
PositionIni := TMemIniFile.Create(aFileName);
try
for ndx := 0 to Pred(aForm.ComponentCount) do
begin
CurrentCompo := aForm.Components[ndx];
if (CurrentCompo is TImage) then
begin
with (CurrentCompo as TImage) do
begin
Top := PositionIni.ReadInteger(Name, 'Top', 0);
Width := PositionIni.ReadInteger(Name, 'Width', 0);
end;
end;
end;
// PositionIni.UpdateFile; // Das UpDateFile ist beim lesen natürlich blödniss gewesen.
finally
PositionIni.free;
end;
end;
procedure TDemoForm.FormCreate(Sender: TObject);
begin
myIniFile := ExtractFilePath(ParamStr(0)) + 'position.ini';
if FileExists(myIniFile) then
begin
LoadImagePos(self,myIniFile);
end;
end;
procedure TDemoForm.FormDestroy(Sender: TObject);
begin
SaveImagePos(self,myIniFile);
end;
Stephan B. "Lasst den Gänsen ihre Füßchen"
|
|
Zitat
|