What goes wrong with this piece of code

Hi everyone,

I want to use the piece of code below, but it locks up my system. If I
replace the line 7 with an empty statement I works fine. If I make a new
project with just a button which executes this code when pressed, it works
fine too, even with line 7. Does anybody know what the problem could be?

1 procedure TOptionsForm.ButtonbestandClick(Sender: TObject);
2 var
3   SystemDir: Array[0..256] of char;
4 begin
5   getSystemDirectory(@SystemDir,SizeOf(SystemDir));
6   if DialoogOpen.InitialDir = '' then
7      DialoogOpen.InitialDir := SystemDir;
8   if DialoogOpen.Execute then
9   begin
10    PanelScreensaver.Caption := ExtractFilename(DialoogOpen.FileName);
11    DialoogOpen.InitialDir := ExtractFilePath(DialoogOpen.FileName);
12    DialoogOpen.FilterIndex := 1;
13  end;
14end;

The purpose of this piece of code is to use an TOpenDialog to put the name
of the screensaver selected by the user in a panel (line 10). I want to
start in the systemdirectory, but the second time to start in the directory
that the user changed to.

Thank in advance,

Peter Schram