dat moet kunnen met TRegistry maar ik weet niet waar de sleutel staat (windows 2000). Makkelijker moeten het ook kunnen met GetTempPath(DWORD nBufferLength, LPTSTR lpBuffer) , maar dat krijg ik ook niet aan de praat , denk doordat ik iets niet goed doe met de bijbehorende paramethers. Graag een stukje code hoe het moet.
Ik heb Delphi hier nu niet geinstalleerd staan, maar wat zegt de help over die GetTempPath functie?
Kun je ook niet uit de voeten door de environment variable %temp% op te vragen?
Kun je ook niet uit de voeten door de environment variable %temp% op te vragen?
https://fgheysels.github.io/
Verwijderd
Hoe doe je het nu?maar dat krijg ik ook niet aan de praat , denk doordat ik iets niet goed doe
in c++ doe je iets als:
code:
1
2
| char buffer[MAX_PATH]; GetTempPath(MAX_PATH, buffer); |
he GetTempPath function retrieves the path of the directory designated for temporary files. This function supersedes the GetTempDrive function.
DWORD GetTempPath(
DWORD nBufferLength, // size, in characters, of the buffer
LPTSTR lpBuffer // address of buffer for temp. path
);
Parameters
nBufferLength
Specifies the size, in characters, of the string buffer identified by lpBuffer.
lpBuffer
Points to a string buffer that receives the null-terminated string specifying the temporary file path.
Return Values
If the function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. If the return value is greater than nBufferLength, the return value is the size of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The GetTempPath function gets the temporary file path as follows:
1. The path specified by the TMP environment variable.
2. The path specified by the TEMP environment variable, if TMP is not defined.
3. The current directory, if both TMP and TEMP are not defined.
ik had het zo gedacht maar dan krijg ik een error tijdens het runnen:
var
temp :Cardinal;
temp3:PChar;
begin
temp:=100;
temp3:='';
GetTempPath( temp, temp3);
end;
DWORD GetTempPath(
DWORD nBufferLength, // size, in characters, of the buffer
LPTSTR lpBuffer // address of buffer for temp. path
);
Parameters
nBufferLength
Specifies the size, in characters, of the string buffer identified by lpBuffer.
lpBuffer
Points to a string buffer that receives the null-terminated string specifying the temporary file path.
Return Values
If the function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. If the return value is greater than nBufferLength, the return value is the size of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The GetTempPath function gets the temporary file path as follows:
1. The path specified by the TMP environment variable.
2. The path specified by the TEMP environment variable, if TMP is not defined.
3. The current directory, if both TMP and TEMP are not defined.
ik had het zo gedacht maar dan krijg ik een error tijdens het runnen:
var
temp :Cardinal;
temp3:PChar;
begin
temp:=100;
temp3:='';
GetTempPath( temp, temp3);
end;
Delphi:
1
2
3
4
5
6
7
8
9
| Function GetTempDir: String; var buf: array[0..MAX_PATH] of Char; begin GetTempPath( Sizeof(buf), buf ); Result := buf; If Result[Length(Result)] <> '\' Then Result := Result + '\'; end; |
Uhm PChar is toch gewoon een pointer... ik zou daar een array van 100 chars in reserveren aub.tyball schreef op 17 september 2002 @ 11:55:
ik had het zo gedacht maar dan krijg ik een error tijdens het runnen:
Delphi:
1 2 3 4 5 6 7 8 9 10 11 var temp :Cardinal; temp3:PChar; begin temp:=100; temp3:=''; GetTempPath( temp, temp3); end;
Op deze manier kan ik me een runtime EAccessViolation wel voorstellen.
Ik zou er ook geen 100 van maken, maar MAX_PATH (die is 255 of misschien ondertussen het dubbele
tis ook zo zout als je een error krijgt als je de temp dir opvraagt bij iemand die m niet in c:\temp of c:\windows\temp heeft
Exact expert nodig?
Verwijderd
dan moet je wel length() in plaats van sizeof() gebruiken, want anders krijg je nooit meer dan 4 tekens in je string te staanWOmBaT schreef op 17 september 2002 @ 11:56:
Delphi:
1 2 3 4 5 6 7 8 9 Function GetTempDir: String; var buf: array[0..MAX_PATH] of Char; begin GetTempPath( Sizeof(buf), buf ); Result := buf; If Result[Length(Result)] <> '\' Then Result := Result + '\'; end;
en ik zou buf dan statisch maken, aangezien anders het geheugen kan worden overschreven voordat de waarde wordt gebruikt in de rest van de programma
Verwijderd
Sorry maar dit gaat nergens over. 'buf' statisch maken heeft geen enkele zin. De waarde wordt meteen in Result gezet en meteen als uitkomst van de functie gegeven dus waar heb je het over?Verwijderd schreef op 17 september 2002 @ 14:00:
[...]
dan moet je wel length() in plaats van sizeof() gebruiken, want anders krijg je nooit meer dan 4 tekens in je string te staan
en ik zou buf dan statisch maken, aangezien anders het geheugen kan worden overschreven voordat de waarde wordt gebruikt in de rest van de programma
Ach hij gaf als size 100 aan, dus vandaarCrazy_D schreef op 17 september 2002 @ 13:09:
Ik zou er ook geen 100 van maken, maar MAX_PATH (die is 255 of misschien ondertussen het dubbeletis ook zo zout als je een error krijgt als je de temp dir opvraagt bij iemand die m niet in c:\temp of c:\windows\temp heeft
Delphi:
1
2
3
4
5
6
| var PathName: array[0..MAX_PATH] of Char; begin GetTempPath(MAX_PATH, @PathName); ShowMessage(PathName); end; |
Delphi:
1
2
3
4
5
6
| var NewTempName: array[0..MAX_PATH] of Char; begin GetTempFileName(PathName, 'XYZ', 0, @NewTempName); ShowMessage(NewTempName); end; |
Een goede grap mag vrienden kosten.
code:
1
2
| If Result[Length(Result)] <> '\' Then
Result := Result + '\'; |
Is een functie voor toch: IncludeTrailingPathDelimiter:
IncludeTrailingPathDelimiter ensures that a path name ends with a trailing path delimiter ('\" on Windows, '/' on Linux). If S already ends with a trailing delimiter character, it is returned unchanged; otherwise S with appended delimiter character is returned.
Note: IncludeTrailingPathDelimiter works with multibyte character sets.
"The shell stopped unexpectedly and Explorer.exe was restarted."
Pagina: 1