Is there an other way to retrieve windows temporary path from the registry?
_________________________________
Here's the code :
function ...
var
Temp : PChar;
begin
try
GetTempPath(max_path,Temp);
except
end;
end;
Regards,
Stephane
ś:-)
Stephane
Shannon Broskie <shannon...@tagfolio.com> wrote in message
news:39453eef@dnews...
> Here's what I use...
>
> procedure GetTempWorkPath;
> (* Procedure: GetTempWorkPath
> *)
> (* Description: Place the Windows temporary path into the TempPath global
> *)
> (* variable.
> *)
> var
> PPath : array[0..255] of char;
> begin
> GetTempPath (SizeOf (PPath), PPath);
> TempPath := Trim(PPath);
> end;
>
> "Stephane Veillette" <veill...@biotonix.com> wrote in message
> news:8i3bi2$ct...@bornews.borland.com...
>I'm using GetTempPath function but I always got "access violation" at the
>end of the function (not during execution).
You never allocate memory to hold the result of GetTempPath. a PChar
variable is merely a pointer; until you allocate memory for it, it
points to a random memory address, and that's what causes the access
violation.
Using a PChar, you'd need to do something like this:
var
Temp: PChar;
begin
Temp := StrAlloc(MAX_PATH);
try
GetTempPath(MAX_PATH, Temp);
// use the result here
finally
StrDispose(Temp) end end;
>begin
> try
> GetTempPath(max_path,Temp);
> except
> end;
>end;
I want you to go to the blackboard right now and write the following
sentence 1000 times:
I will NEVER again write an empty EXCEPT clause.
I will NEVER again write an empty EXCEPT clause.
I will NEVER again write an empty EXCEPT clause.
...
By writing an empty EXCEPT clause, you are saying "I don't care if my
program contains a nasty bug that could corrupt data or cause the
computer to crash; I don't want to know about it."
-Steve
GetMem(Temp,Max_path+1);
That would assign a bunch of bytes to a pointer TEMP and then your GetTempPath
would work, then before exiting your routine you shouold free up the memory you
just allocated otherwise you end up with memory leaks :) So then you could do
this
FreeMem(Temp, Max_path+1);
Davie
Stephane Veillette wrote:
> Hi,
> I'm using GetTempPath function but I always got "access violation" at the
> end of the function (not during execution). If I remove the GetTempPath
> function from the program, everything is ok.
>
> Is there an other way to retrieve windows temporary path from the registry?
>
> _________________________________
> Here's the code :
>
> function ...
> var
> Temp : PChar;
> begin
> try
> GetTempPath(max_path,Temp);
> except
> end;
> end;
>
> Regards,
> Stephane