Re:INDY MessageSaveLoad Demo - Would like to open Attachments from this demo
to open a file with the default action, you would use ShellExec
I will include an example for "open" below
uses ShellAPI;
procedurte TForm1.OpenAFile(S: string);
var
TheHandle: THandle;
begin
TheHandle:=ShellExecute(Application.Handle,'Open',PChar(s),nil,nil,SW_SHOW);
if TheHandle<=HINSTANCE_ERROR then
raise Exception.Create('Unable to run ShellExec. Error
code='+IntToStr(TheHandle));
end;
some other useful bits below (maybe)
(handle, cmd, file, paramaters, default dir, state)
case TheHandle of
0: S:= '0 - OOM resources';
// ERROR_FILE_NOT_FOUND: S := 'ERROR_FILE_NOT_FOUND';
// ERROR_PATH_NOT_FOUND : S := 'ERROR_PATH_NOT_FOUND';
ERROR_BAD_FORMAT : S := 'ERROR_BAD_FORMAT';
SE_ERR_ACCESSDENIED : S := 'The operating system denied access to the
specified file.';
SE_ERR_ASSOCINCOMPLETE: S := 'The filename association is incomplete or
invalid.';
SE_ERR_DDEBUSY : S := 'The DDE transaction could not be completed because
other DDE transactions were being processed.';
SE_ERR_DDEFAIL : S := 'The DDE transaction failed.';
SE_ERR_DDETIMEOUT : S := 'The DDE transaction could not be completed because
the request timed out.';
SE_ERR_DLLNOTFOUND : S := 'The specified dynamic-link library was not
found.';
SE_ERR_FNF : S := 'The specified file was not found.';
SE_ERR_NOASSOC : S := 'There is no application associated with the given
filename extension.';
SE_ERR_OOM : S := 'There was not enough memory to complete the operation.';
SE_ERR_PNF : S := 'The specified path was not found.';
SE_ERR_SHARE : S := 'A sharing violation occurred.';
else S := 'Dunno';
end;
raise Exception.Create('Unable to run ShellExec. Error
code='+IntToStr(TheHandle)+ #10#13 + S)
Quote
"M Tuttle" <mi...@softtechks.com> wrote in message
news:3e948f8a$1@newsgroups.borland.com...
Quote
> Greetings All,
> Very new to INDY as of today.
> I'm using the MessageSaveLoad Demo from INDY 9 for this example.
> This is the original code from the btnLoadFromFile procedure that loads
the
> Attachments list.
> ...
> for i := 0 to IdMessage.MessageParts.Count - 1 do
> if IdMessage.MessageParts.Items[i] is TidText then
> mmoBody.Lines.AddStrings(TidText(IdMessage.MessageParts.Items[i]).Body)
> else if IdMessage.MessageParts.Items[i] is TidAttachment then
lbAttach.items.Append(TidAttachment(IdMessage.MessageParts.Items[i]).FileNam
Quote
> e);
> ...
> How could I modify this sample so the user could double click on any
> attachment in the Attachment list and the appropriate file would open? So
> if it is a zip file then winzip would start up and open the zip file.
> Any sample code would greatly be appreciated.
> Thanks
> Michael Tuttle
> Software Technologies, Inc.
> Topeka, KS