ik heb een programmaatje geschreven met delphi 5 voor het openen van PDF bestanden.
Ik laat via een listbox een veld invullen in Tedit.
In Tedit staat dan het path en de naam van het PDF bestand. Via een button probeer ik dan het pdf-bestand te openen. maar het lukt niet.
Het volgende functies probeer ik hiervoor te gebruiken:
docfilename := edit.text;
docfiledir := extractfiledir(docfilename);
shellexecute(0, nil,
PChar(docfilename),nil,
PChar(docfiledir), SW_hide);
Weet iemand hoe je dit kan oplossen.
------------------
Short translation, by the webmaster:
My Delphi 5 program should open a PDF file. There's a TEdit for the path and the
name of the file. But it doesn't work, when I use this code: (...)
Try to eliminate the possible errors step by step:
1. Test by hard-coding the full path of a known file. For clearity, combine the path
and the filename, such as:
DocFullPath := 'c:\test\myfile.pdf';
if FileExists(DocFullPath) then
ShellExecute(Handle, 'open', PChar('DocFullPath), nil, nil, SW_SHOW)
else
ShowMessage('File not found: ' + DocFullPath);
2. Next, assemble the full path, as it will be done in the "real" program:
DocDir := 'c:\test';
if DocDir[Length(DocDir)] <> '\' then
DocDir := DocDir + '\';
DocName := 'myfile.pdf';
DocFullPath := DocDir + DocName;
if FileExists(DocFullPath) then
ShellExecute(Handle, 'open', PChar(DocFullPath), nil, nil, SW_SHOW)
else
ShowMessage('File not found: ' + DocFullPath);
3. Next, test with two edit-boxes:
DocDir := Edit1.Text;
if DocDir[Length(DocDir)] <> '\' then
DocDir := DocDir + '\';
DocName := Edit2.Text;
DocFullPath := DocDir + DocName;
if FileExists(DocFullPath) then
ShellExecute(Handle, 'open', PChar(DocFullPath), nil, nil, SW_SHOW)
else
ShowMessage('File not found: ' + DocFullPath);
In DelphiLand's "Source Snips" section, you can see several other examples, plus a
link to a downloadable fully operational example project, EXEWAIT.ZIP.
===============================
Probeer een voor een de mogelijke fouten te elimineren:
1. Test eerst door zelf een volledige path van een bestand te geven. Voor de duidelijkheid
combineer ik de bestandsnaam en directory in 1 parameter. Voorbeeld:
DocFullPath := 'c:\test\bestand.pdf';
if FileExists(DocFullPath) then
ShellExecute(Handle, 'open', PChar('DocFullPath), nil, nil, SW_SHOW)
else
ShowMessage('Bestand niet gevonden: ' + DocFullPath);
2. Stel vervolgens het volledige path samen zoals het later "in het echt" zal gebeuren:
DocDir := 'c:\test';
if DocDir[Length(DocDir)] <> '\' then
DocDir := DocDir + '\';
DocName := 'bestand.pdf';
DocFullPath := DocDir + DocName;
if FileExists(DocFullPath) then
ShellExecute(Handle, 'open', PChar(DocFullPath), nil, nil, SW_SHOW)
else
ShowMessage('Bestand niet gevonden: ' + DocFullPath);
3. Test nu met twee edit-boxen:
DocDir := Edit1.Text;
if DocDir[Length(DocDir)] <> '\' then
DocDir := DocDir + '\';
DocName := Edit2.Text;
DocFullPath := DocDir + DocName;
if FileExists(DocFullPath) then
ShellExecute(Handle, 'open', PChar(DocFullPath), nil, nil, SW_SHOW)
else
ShowMessage('Bestand niet gevonden: ' + DocFullPath);
In het Engelstalige gedeelte van DelphiLand staan overigens in de "Source Snips" sectie
een aantal andere voorbeelden. Het artikeltje is aangevuld met een te downloaden volledig
uitgewerkt voorbeeld-project, EXEWAIT.ZIP.