/ Forside / Teknologi / Udvikling / Delphi/Pascal / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Delphi/Pascal
#NavnPoint
oldwiking 603
jrossing 525
rpje 520
EXTERMINA.. 500
gandalf 460
gubi 270
DJ_Puden 250
PARKENSS 230
technet 210
10  jdjespers.. 200
'CopyFile' og 'CopyFileEx' - Error: 2 v/Ge~
Fra : Alex B. P.


Dato : 08-04-03 18:51

Hej NG !

Hvorfor kopierer følgende kode ikke filerne, Returnerer en ERROR = 2 ved
GetLastError.

Det er meningen, at nogle filer, som udpeges i anden unit, via TOpenDialog,
giver en "TStrings" som jeg itererer gennem, og vil så kopiere fra den
fil-navn, til en lokal temp folder under Prog-run-time.
Kompilerer og kører fint, men ingen filer kopieres ???

----------------------

Procedure
TTeleEmail.PackReplyEmlAttachments(SubFolder,EmlFileNameAndExt:String;VAR
ChilkatEmailObj:ChilkatEmail;OutAttFileNames:TStrings;VAR
NumOfAttFiles:Byte);
VAR
idx:Byte;

OutAttachmentSavePath,NewTempAttachmentDir,SourceFile,TargetFile:WideString;
pCancel,dummyPointer:Pointer;
dwCopyFlags:Word;
debugDummy1:String;
searchResult:TSearchRec;
sRes:Integer;
resCopyFile:LongBool;
Begin
idx := 0;
NewTempAttachmentDir := CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + OutAttachmentsSubFolder;
NumOfAttFiles := OutAttFileNames.Count;
ChilkatEmailObj.Mailer := DefaultXMailerTag;
try
MkDir(NewTempAttachmentDir);
if IOResult <> 0 then
Log('Cannot create directory ... - '+NewTempAttachmentDir)
else
Log('New directory created ... - '+NewTempAttachmentDir);
except
Log('Cannot create directory ... - '+NewTempAttachmentDir);
end;

OutAttachmentSavePath := CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + OutAttachmentsSubFolder + '\';
//pCancel:=Addr(Cancel);
dwCopyFlags := COPY_FILE_RESTARTABLE;

IF (NumOfAttFiles > 0) THEN
try
// Copy file(s)
//CopyFileEx(SourceFile,TargetFile,NULL,NULL,pCancel,dwCopyFlags);
FOR idx := 0 TO NumOfAttFiles-1 DO
Begin
SourceFile := OutAttFileNames[idx];
//TargetFile := OutAttachmentSavePath + '*.*';
TargetFile := OutAttachmentSavePath + ExtractFileName(SourceFile);
----------------------------------------------------------------------------
--------------------------------------------------------------------------->
>>>>>>
//CopyFile(PChar(SourceFile),PChar(TargetFile),FALSE);
IF not
Windows.CopyFileEx(PChar(SourceFile),PChar(TargetFile),dummyPointer,dummyPoi
nter,pCancel,dwCopyFlags) then
Log('Copy file failed, error ' + IntToStr (GetLastError));
----------------------------------------------------------------------------
--------------------------------------------------------------------------<<
<<<<<
debugDummy1 := 'pause';
end;
except
// Handles copy error(s)
Log('TeleEmail01.PackReplyEmlAttachments-> Error: OutAttachmentFile
could was not copied correctly/not found');
end; // try .. except

sRes := FindFirst(OutAttachmentSavePath + '*.*',faAnyFile,searchResult);
IF sRes = 0 THEN // = = Result was success, files found
try // try (2)
While sRes = 0 DO
Begin
//IF (searchResult.Attr and faDirectory) <> faDirectory THEN
Begin
if (searchResult.Name <> '') THEN
ChilkatEmailObj.AddFileAttachment(OutAttachmentSavePath +
searchResult.Name);
end;
sRes := FindNext(searchResult);
end;
//except
//Handle exception
finally
FindClose(searchResult);
end; // end ... try (2)
ChilkatEmailObj.SaveEml(CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + ReplyEmailNameInZip);

end;

-------------------------->>>
Her kaldes proceduren med relevante parametre

function TTeleEmail.AddAttToReplyEmail(ContactRespID:String;VAR
OutAttachmentFileNames:TStrings):Integer;
VAR
NumOfAttachments:Byte;
Begin
NumOfAttachments := 0;

TeleEmail.PackReplyEmlAttachments(ContactRespID,ReplyEmailNameInZip,ChilkatE
mailOut,OutAttachmentFileNames,NumOfAttachments);

//TeleEmail.PackReplyEmlAttachments2(ContactRespID,ReplyEmailNameInZip,Chilk
atEmailOut,OutAttachmentFileNames,NumOfAttachments,ReplyAttShellListView);
Log('NumOfOutBound attachments: ' + IntToStr(NumOfAttachments));
end;



 
 
Ole Lund (10-04-2003)
Kommentar
Fra : Ole Lund


Dato : 10-04-03 11:44

en pekepinn er

2 ERROR_FILE_NOT_FOUND

mvh
Ole Lund


"Alex B. P." <alexbp@post.tele.dk> wrote in message
news:3e930bf9$0$24639$edfadb0f@dread14.news.tele.dk...
> Hej NG !
>
> Hvorfor kopierer følgende kode ikke filerne, Returnerer en ERROR = 2 ved
> GetLastError.
>
> Det er meningen, at nogle filer, som udpeges i anden unit, via
TOpenDialog,
> giver en "TStrings" som jeg itererer gennem, og vil så kopiere fra den
> fil-navn, til en lokal temp folder under Prog-run-time.
> Kompilerer og kører fint, men ingen filer kopieres ???
>
> ----------------------
>
> Procedure
> TTeleEmail.PackReplyEmlAttachments(SubFolder,EmlFileNameAndExt:String;VAR
> ChilkatEmailObj:ChilkatEmail;OutAttFileNames:TStrings;VAR
> NumOfAttFiles:Byte);
> VAR
> idx:Byte;
>
>
OutAttachmentSavePath,NewTempAttachmentDir,SourceFile,TargetFile:WideString;
> pCancel,dummyPointer:Pointer;
> dwCopyFlags:Word;
> debugDummy1:String;
> searchResult:TSearchRec;
> sRes:Integer;
> resCopyFile:LongBool;
> Begin
> idx := 0;
> NewTempAttachmentDir := CurrentDir + '\' + TempFileFolder + '\' +
> SubFolder + '\' + OutAttachmentsSubFolder;
> NumOfAttFiles := OutAttFileNames.Count;
> ChilkatEmailObj.Mailer := DefaultXMailerTag;
> try
> MkDir(NewTempAttachmentDir);
> if IOResult <> 0 then
> Log('Cannot create directory ... - '+NewTempAttachmentDir)
> else
> Log('New directory created ... - '+NewTempAttachmentDir);
> except
> Log('Cannot create directory ... - '+NewTempAttachmentDir);
> end;
>
> OutAttachmentSavePath := CurrentDir + '\' + TempFileFolder + '\' +
> SubFolder + '\' + OutAttachmentsSubFolder + '\';
> //pCancel:=Addr(Cancel);
> dwCopyFlags := COPY_FILE_RESTARTABLE;
>
> IF (NumOfAttFiles > 0) THEN
> try
> // Copy file(s)
> //CopyFileEx(SourceFile,TargetFile,NULL,NULL,pCancel,dwCopyFlags);
> FOR idx := 0 TO NumOfAttFiles-1 DO
> Begin
> SourceFile := OutAttFileNames[idx];
> //TargetFile := OutAttachmentSavePath + '*.*';
> TargetFile := OutAttachmentSavePath + ExtractFileName(SourceFile);
> --------------------------------------------------------------------------
--
> --------------------------------------------------------------------------
->
> >>>>>>
> //CopyFile(PChar(SourceFile),PChar(TargetFile),FALSE);
> IF not
>
Windows.CopyFileEx(PChar(SourceFile),PChar(TargetFile),dummyPointer,dummyPoi
> nter,pCancel,dwCopyFlags) then
> Log('Copy file failed, error ' + IntToStr (GetLastError));
> --------------------------------------------------------------------------
--
> --------------------------------------------------------------------------
<<
> <<<<<
> debugDummy1 := 'pause';
> end;
> except
> // Handles copy error(s)
> Log('TeleEmail01.PackReplyEmlAttachments-> Error: OutAttachmentFile
> could was not copied correctly/not found');
> end; // try .. except
>
> sRes := FindFirst(OutAttachmentSavePath + '*.*',faAnyFile,searchResult);
> IF sRes = 0 THEN // = = Result was success, files found
> try // try (2)
> While sRes = 0 DO
> Begin
> //IF (searchResult.Attr and faDirectory) <> faDirectory THEN
> Begin
> if (searchResult.Name <> '') THEN
> ChilkatEmailObj.AddFileAttachment(OutAttachmentSavePath +
> searchResult.Name);
> end;
> sRes := FindNext(searchResult);
> end;
> //except
> //Handle exception
> finally
> FindClose(searchResult);
> end; // end ... try (2)
> ChilkatEmailObj.SaveEml(CurrentDir + '\' + TempFileFolder + '\' +
> SubFolder + '\' + ReplyEmailNameInZip);
>
> end;
>
> -------------------------->>>
> Her kaldes proceduren med relevante parametre
>
> function TTeleEmail.AddAttToReplyEmail(ContactRespID:String;VAR
> OutAttachmentFileNames:TStrings):Integer;
> VAR
> NumOfAttachments:Byte;
> Begin
> NumOfAttachments := 0;
>
>
TeleEmail.PackReplyEmlAttachments(ContactRespID,ReplyEmailNameInZip,ChilkatE
> mailOut,OutAttachmentFileNames,NumOfAttachments);
>
>
//TeleEmail.PackReplyEmlAttachments2(ContactRespID,ReplyEmailNameInZip,Chilk
> atEmailOut,OutAttachmentFileNames,NumOfAttachments,ReplyAttShellListView);
> Log('NumOfOutBound attachments: ' + IntToStr(NumOfAttachments));
> end;
>
>



Alex B. P. (14-04-2003)
Kommentar
Fra : Alex B. P.


Dato : 14-04-03 16:31

Løsning på CopyFile - fejl fundet: -> Lukker selv !

Det er ved en CAST'ing af WideString -> PChar, der åbenbart sker en
fejl-ref.

Jeg skiftede WideString VAR'en ud med alm. String som et sidste
desperat/tilfældigt forsøgt, og så virkede alt pludseligt.

Jeg må så nøjes p.t. med path + filnavn på max: 255 bytes + 1 byte til
length.

Ny 'sovs', der kører:
-------------------------->>>
Procedure
TTeleEmail.PackReplyEmlAttachments(SubFolder,EmlFileNameAndExt:String;VAR
ChilkatEmailObj:ChilkatEmail;OutAttFileNames:TStrings;VAR
NumOfAttFiles:Byte);
VAR
idx:Byte;
OutAttachmentSavePath,NewTempAttachmentDir,SourceFile,TargetFile:String;
pCancel,dummyPointer:Pointer;
dwCopyFlags:Word;
debugDummy1:String;
searchResult:TSearchRec;
sRes:Integer;
resCopyFile:LongBool;
Begin
// Result := 0;
idx := 0;
NewTempAttachmentDir := CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + OutAttachmentsSubFolder;
NumOfAttFiles := OutAttFileNames.Count;
ChilkatEmailObj.Mailer := DefaultXMailerTag;
try
if not DirectoryExists(NewTempAttachmentDir) then
MkDir(NewTempAttachmentDir);
if IOResult <> 0 then
Log('Cannot create directory ... - '+NewTempAttachmentDir)
else
Log('New directory created ... - '+NewTempAttachmentDir);
except
Log('Cannot create directory ... - '+NewTempAttachmentDir);
end;

OutAttachmentSavePath := CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + OutAttachmentsSubFolder + '\';
//pCancel:=Addr(Cancel);
dwCopyFlags := COPY_FILE_RESTARTABLE;

IF (NumOfAttFiles > 0) THEN
try
// Copy file(s)
//CopyFileEx(SourceFile,TargetFile,NULL,NULL,pCancel,dwCopyFlags);
FOR idx := 0 TO NumOfAttFiles-1 DO
Begin
SourceFile := OutAttFileNames[idx];
//TargetFile := OutAttachmentSavePath + '*.*';
TargetFile := OutAttachmentSavePath + ExtractFileName(SourceFile);
// Virker ikke sådan ...??
//if FileExists(SourceFile) then
// CopyFile(PChar(SourceFile),PChar(TargetFile),FALSE);
IF not
Windows.CopyFileEx(PChar(SourceFile),PChar(TargetFile),dummyPointer,dummyPoi
nter,pCancel,dwCopyFlags) then
Log('Copy file failed, error ' + IntToStr (GetLastError));

debugDummy1 := 'pause';
end;
except
// Handles copy error(s)
Log('TeleEmail01.PackReplyEmlAttachments-> Error: OutAttachmentFile
could was not copied correctly/not found');
end; // try .. except

sRes := FindFirst(OutAttachmentSavePath + '*.*',faAnyFile,searchResult);
IF sRes = 0 THEN // = = Result was success, files found
try // try (2)
While sRes = 0 DO
Begin
IF (searchResult.Attr and faDirectory) <> faDirectory THEN
Begin
if (searchResult.Name <> '') THEN
ChilkatEmailObj.AddFileAttachment(OutAttachmentSavePath +
searchResult.Name);
end;
sRes := FindNext(searchResult);
end;
//except
//Handle exception
finally
FindClose(searchResult);
end; // end ... try (2)
ChilkatEmailObj.SaveEml(CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + ReplyEmailNameInZip);

TeleEmail.DynamicOutAttachmentsRoot := OutAttachmentSavePath;
end;
------------------->>>

Mvh -> Alex
"Alex B. P." <alexbp@post.tele.dk> wrote in message
news:3e930bf9$0$24639$edfadb0f@dread14.news.tele.dk...
> Hej NG !
>
> Hvorfor kopierer følgende kode ikke filerne, Returnerer en ERROR = 2 ved
> GetLastError.
>
> Det er meningen, at nogle filer, som udpeges i anden unit, via
TOpenDialog,
> giver en "TStrings" som jeg itererer gennem, og vil så kopiere fra den
> fil-navn, til en lokal temp folder under Prog-run-time.
> Kompilerer og kører fint, men ingen filer kopieres ???
>
> ----------------------
>
> Procedure
> TTeleEmail.PackReplyEmlAttachments(SubFolder,EmlFileNameAndExt:String;VAR
> ChilkatEmailObj:ChilkatEmail;OutAttFileNames:TStrings;VAR
> NumOfAttFiles:Byte);
> VAR
> idx:Byte;
>
>
OutAttachmentSavePath,NewTempAttachmentDir,SourceFile,TargetFile:WideString;
> pCancel,dummyPointer:Pointer;
> dwCopyFlags:Word;
> debugDummy1:String;
> searchResult:TSearchRec;
> sRes:Integer;
> resCopyFile:LongBool;
> Begin
> idx := 0;
> NewTempAttachmentDir := CurrentDir + '\' + TempFileFolder + '\' +
> SubFolder + '\' + OutAttachmentsSubFolder;
> NumOfAttFiles := OutAttFileNames.Count;
> ChilkatEmailObj.Mailer := DefaultXMailerTag;
> try
> MkDir(NewTempAttachmentDir);
> if IOResult <> 0 then
> Log('Cannot create directory ... - '+NewTempAttachmentDir)
> else
> Log('New directory created ... - '+NewTempAttachmentDir);
> except
> Log('Cannot create directory ... - '+NewTempAttachmentDir);
> end;
>
> OutAttachmentSavePath := CurrentDir + '\' + TempFileFolder + '\' +
> SubFolder + '\' + OutAttachmentsSubFolder + '\';
> //pCancel:=Addr(Cancel);
> dwCopyFlags := COPY_FILE_RESTARTABLE;
>
> IF (NumOfAttFiles > 0) THEN
> try
> // Copy file(s)
> //CopyFileEx(SourceFile,TargetFile,NULL,NULL,pCancel,dwCopyFlags);
> FOR idx := 0 TO NumOfAttFiles-1 DO
> Begin
> SourceFile := OutAttFileNames[idx];
> //TargetFile := OutAttachmentSavePath + '*.*';
> TargetFile := OutAttachmentSavePath + ExtractFileName(SourceFile);
> --------------------------------------------------------------------------
--
> --------------------------------------------------------------------------
->
> >>>>>>
> //CopyFile(PChar(SourceFile),PChar(TargetFile),FALSE);
> IF not
>
Windows.CopyFileEx(PChar(SourceFile),PChar(TargetFile),dummyPointer,dummyPoi
> nter,pCancel,dwCopyFlags) then
> Log('Copy file failed, error ' + IntToStr (GetLastError));
> --------------------------------------------------------------------------
--
> --------------------------------------------------------------------------
<<
> <<<<<
> debugDummy1 := 'pause';
> end;
> except
> // Handles copy error(s)
> Log('TeleEmail01.PackReplyEmlAttachments-> Error: OutAttachmentFile
> could was not copied correctly/not found');
> end; // try .. except
>
> sRes := FindFirst(OutAttachmentSavePath + '*.*',faAnyFile,searchResult);
> IF sRes = 0 THEN // = = Result was success, files found
> try // try (2)
> While sRes = 0 DO
> Begin
> //IF (searchResult.Attr and faDirectory) <> faDirectory THEN
> Begin
> if (searchResult.Name <> '') THEN
> ChilkatEmailObj.AddFileAttachment(OutAttachmentSavePath +
> searchResult.Name);
> end;
> sRes := FindNext(searchResult);
> end;
> //except
> //Handle exception
> finally
> FindClose(searchResult);
> end; // end ... try (2)
> ChilkatEmailObj.SaveEml(CurrentDir + '\' + TempFileFolder + '\' +
> SubFolder + '\' + ReplyEmailNameInZip);
>
> end;
>
> -------------------------->>>
> Her kaldes proceduren med relevante parametre
>
> function TTeleEmail.AddAttToReplyEmail(ContactRespID:String;VAR
> OutAttachmentFileNames:TStrings):Integer;
> VAR
> NumOfAttachments:Byte;
> Begin
> NumOfAttachments := 0;
>
>
TeleEmail.PackReplyEmlAttachments(ContactRespID,ReplyEmailNameInZip,ChilkatE
> mailOut,OutAttachmentFileNames,NumOfAttachments);
>
>
//TeleEmail.PackReplyEmlAttachments2(ContactRespID,ReplyEmailNameInZip,Chilk
> atEmailOut,OutAttachmentFileNames,NumOfAttachments,ReplyAttShellListView);
> Log('NumOfOutBound attachments: ' + IntToStr(NumOfAttachments));
> end;
>
>



Olav M.J. Christians~ (26-04-2003)
Kommentar
Fra : Olav M.J. Christians~


Dato : 26-04-03 08:57

"Alex B. P." <alexbp@post.tele.dk> skrev i en meddelelse
news:3e9ad41f$0$24706$edfadb0f@dread14.news.tele.dk...
[klip]
> Jeg skiftede WideString VAR'en ud med alm. String som
> et sidste desperat/tilfældigt forsøgt, og så virkede alt pludseligt.
>
> Jeg må så nøjes p.t. med path + filnavn på max: 255 bytes + 1
> byte til length.
[klip]

Nu har jeg ikke gransket dit eksempel nærmere, og faldt blot tilfældigt
over din post idag, men jeg undrer mig over noget:

Det lyder på det du skriver som om en WideString skulle kunne være
længere end en String. Det er ikke tilfældet. En WideString er *bredere*
end en almindelig String - ikke længere. Det vil sige at hvert tegn
fylder 16 bits og ikke 8 som normalt. Se her et udklip fra Delphis
hjælpefil:

Type Maximum length Memory required Used for
ShortString 255 characters 2 to 256 bytes backward compatibility
AnsiString ~2^31 characters 4 bytes to 2GB 8-bit (ANSI) characters
WideString ~2^30 characters 4 bytes to 2GB Unicode characters;
multiuser servers and multi-language applications
AnsiString, sometimes called the long string, is the preferred type for
most purposes.

Kun hvis du bruger compiler-direktivet {$H-}vil den opfatte en String
som en ShortString.

--
M.v.h.
Olav
http://www.jydholm.dk



Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408924
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste