Adding attachment if custom checkbox in assistant is checked

delphi package - automated exception handling
Post Reply
format71
Posts: 8
Joined: Thu Jan 21, 2010 8:29 pm

Adding attachment if custom checkbox in assistant is checked

Post by format71 »

Hi,

I want to give my customer the possibility to add data files to the bug report.

I have added a custom checkbox to the send assistant, but how can I check for the value of this checkbox and attach the necessary files before sending?

regards,
-Vegar
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You can define your own "OnAction" handler (this is a property of an assistant form). In your OnAction handler you can check for "nvaItemEvent" (check box state was changed) or for "nvaFormClose" and then do whatever you want to do. E.g. call GetOpenFileName and then attach the selected file(s) to the exception. More information here:

http://help.madshi.net/madNVAssistantUnit.htm
format71
Posts: 8
Joined: Thu Jan 21, 2010 8:29 pm

Post by format71 »

Thanks,

I tried to assign an OnAction-event, but found it easier to use the ExceptAction-event on the VCL component.

I have a small problem, though.

Code: Select all

procedure TMainForm.MadExceptionHandler1ExceptAction(action: TExceptAction;
  const exceptIntf: IMEException; var handled: Boolean);
var
  cbSendData: INVCheckbox;
  zipfile: String;
  assistant: INVAssistant;
begin
  if (action = eaSendBugReport) then
  begin
    assistant := exceptIntf.GetAssistant(exceptIntf.SendAssistant);
    cbSendData := assistant.Forms[1].nvCheckBox('SendDataChk');

    cbSendData.Enabled := HasData;
    cbSendData.Checked := HasData;
  end
  else if action = eaSendBugReport2 then
  begin
    assistant := exceptIntf.GetAssistant(exceptIntf.SendAssistant);
    cbSendData := assistant.Forms[1].nvCheckBox('SendDataChk');

    exceptIntf.AdditionalAttachments.Clear;
    if cbSendData.Checked then
      exceptIntf.AdditionalAttachments.Add(datafile);
  end;
end;
When action equals eaSendBugReport, I disable the checkbox if no data exists, but when the assistant pops up, the checkbox is still enabled.

Do you have a solution for this?

regards,
-Vegar
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Calling "GetAssistant" returns a new instance of the specified assistant and any changes you do only apply to this new instance. Once your local variable "assistant" goes out of scope, the new instance is destroyed and all your changes are lost.

You can manually show the assistant, if you want, by doing "assistant.ShowModal", but that way you are bypassing the normal madExcept chain of action. So if you do this, you should disable the assistant in the madExcept settings so that madExcept doesn't show the same assistant another time after you've shown the modified instance.

Of course the cleanest approach is the one I suggested in my first comment.
format71
Posts: 8
Joined: Thu Jan 21, 2010 8:29 pm

Post by format71 »

OK. I will see if I make a second attempt tomorrow, or just skip the first part, and ignore the checkbox if no data exists.

I'm still using the evaluation/noncommercial version. Guess everything will get easier once I get the source. :-)

thanks,
-Vegar
Post Reply