strange behaviour
From: Nicolai Hansen (nic_at_aub.dk)
Date: 10/24/03
- Next message: J French: "Re: Assigning Customs fonts to a canvas"
- Previous message: Paul: "Re: Stupid newbie question - Qdialogs/dialogs?"
- Next in thread: J French: "Re: strange behaviour"
- Reply: J French: "Re: strange behaviour"
- Reply: Jeremy Collins: "Re: strange behaviour"
- Reply: AlanGLLoyd: "Re: strange behaviour"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Oct 2003 00:51:26 -0700
Hi guys,
In an application I need to get the folder in which Windows are
installed.
My first attempt was:
var
p: PChar;
s: String;
begin
GetWindowsDirectory(p, 256);
s:=p;
Showmessage(s); <---
Showmessage('done');
end;
which crashed on the marked line (need to say that both s and p got
the right values, c:\winnt)
Second attempt:
var
p: PChar;
s: String;
begin
GetWindowsDirectory(p, 256);
s:=p;
Showmessage('done'); <---
end;
weird.. Third attempt:
var
p: PChar;
s: String;
begin
new(p);
GetWindowsDirectory(p, 256);
s:=p;
Showmessage('done');
dispose(p);
end;
which works! I thought, 'great!' and did:
var
p: PChar;
s: String;
begin
new(p);
GetWindowsDirectory(p, 256);
s:=p;
Showmessage(s); <---
Showmessage('done');
dispose(p);
end;
Crash again. I then tried
var
p: PChar;
s: String;
i: Integer;
begin
i:=GetWindowsDirectory(p, 256);
s:=copy(p, 1, i);
Showmessage(s); <---
Showmessage('done');
end;
but nope. I changed it back to the working, with a little
modification:
var
p: PChar;
s: String;
begin
new(p);
GetWindowsDirectory(p, 256);
s:=p;
dispose(p);
Showmessage('done'); <---
end;
In the end I made it work by declaring the pchar global and
new/dispose in oncreate/ondestroy. But why, oh why, does it behave
like this?
/Nic
- Next message: J French: "Re: Assigning Customs fonts to a canvas"
- Previous message: Paul: "Re: Stupid newbie question - Qdialogs/dialogs?"
- Next in thread: J French: "Re: strange behaviour"
- Reply: J French: "Re: strange behaviour"
- Reply: Jeremy Collins: "Re: strange behaviour"
- Reply: AlanGLLoyd: "Re: strange behaviour"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|