Board index » delphi » What's wrong with this piece of code

What's 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

 

Re:What's wrong with this piece of code


Quote
Peter wrote:
> 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

Just a quick thought, would it work if you change line 7 to:

DialoogOpen.InitialDir :=  String(SystemDir);

James

Re:What's wrong with this piece of code


Quote
>Just a quick thought, would it work if you change line 7 to:

>DialoogOpen.InitialDir :=  String(SystemDir);

>James

Yes it does, but how can this hang my whole system?

Anyway, thanks a lot.

Peter Schram

Re:What's wrong with this piece of code


Quote
Peter wrote:
> >Just a quick thought, would it work if you change line 7 to:

> >DialoogOpen.InitialDir :=  String(SystemDir);

> >James

> Yes it does, but how can this hang my whole system?

> Anyway, thanks a lot.

> Peter Schram

I am not sure I can answer this one.  I am just glad it works.  Debuggin
is like trying everything you usually think irrational until it works,
then dont ask why.  API guru Peter Below from Team B probably can give
you some hint.  But I am not surprised just counting how many times I
need to reboot Windows each day.  Best wishes.

James

Other Threads