uses ShellApi
function GetAppName(Doc: string): string;
var
FN, DN, RES: array[0..255] of char;
begin
StrPCopy(FN, DOC);
DN[0] := #0;
RES[0] := #0;
FindExecutable(FN, DN, RES);
Result := StrPas(RES);
end;
function GetTempFile(const Extension: string): string;
var
Buffer: array[0..MAX_PATH] of char;
aFile: string;
begin
GetTempPath(SizeOf(Buffer) - 1, Buffer);
GetTempFileName(Buffer, 'TMP', 0, Buffer);
SetString(aFile, Buffer, StrLen(Buffer));
Result := ChangeFileExt(aFile, Extension);
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
var
f: System.Text;
temp: string;
begin
// get a unique temporary file name
temp := GetTempFile('.htm');
// Create the file
AssignFile(f, temp);
rewrite(f);
closefile(f);
// Show the path to the browser
Label1.Caption := (GetAppName(temp));
Label2.Caption := ExtractFileName((GetAppName(temp)));
// Finally delete the temporary file
Erase(f);
end;
Keine Kommentare:
Kommentar veröffentlichen