Moin,
die dynamische Ermittlung des Pfades halte ich hier für die bessere Lösung. Den RootPath würde ich nur einmal ermitteln wollen.
Delphi-Quellcode:
private
ImageRootPath: TFileName;
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
resourcestring
SSUBDIR = 'Maps';
function NodePath(node: TTReeNode; const sDelimiter: string = PathDelim): string;
begin
Result := node.Text;
if Assigned(node.Parent) then
Result := NodePath(node.Parent) + sDelimiter + Result;
end;
procedure TDemoForm.FormCreate(Sender: TObject);
begin
ImageRootPath := IncludeTrailingPathDelimiter(
ExtractFilePath(ParamStr(0)) + SSUBDIR);
end;
procedure TDemoForm.ListChange(Sender: TObject; Node: TTreeNode);
var
fn: TFileName;
begin
with Sender as TTreeView do
if node.Level > 0 then
begin
fn := ImageRootPath + NodePath(node) + '.png';
Current.Picture.LoadFromFile(fn);
Current.SetBounds((Holder.ClientWidth - Current.Width) div 2,
(Holder.ClientHeight - Current.Height) div 2, Current.Width,
Current.Height);
end
end;
Grüße vom marabu