Einzelnen Beitrag anzeigen

Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.492 Beiträge
 
Delphi 7 Enterprise
 
#10

AW: Invalid Class Typecast

  Alt 19. Sep 2013, 11:04
Z.b. so (ungeprüft):
Delphi-Quellcode:
type
  TAttachmentInfo = class
    Ms : TMemorystream;
    Fn : string;
  public
    destructor destroy; override;
  end;

{ TAttachmentInfo }

destructor TAttachmentInfo.destroy;
begin
  if Assigned(Ms) then
    Ms.Free;
  if fn <> 'then
    fn := emptystr;
  inherited;
end;

procedure TTmaintenance_testmailing_form.advGlowBtnClick(Sender: TObject);
var
 i : Integer;
 AttachInfo : TAttachmentInfo;
 AttachInfoList : TObjectList;
begin

   //Check Entries
   If (StringReplace(edt_mailproject.Text, ' ', '', [rfReplaceAll]) = EmptyStr) Or
      (StringReplace(edt_mailapplication.Text, ' ', '', [rfReplaceAll]) = EmptyStr) Or
      (StringReplace(edt_mailsubject.Text, ' ', '', [rfReplaceAll]) = EmptyStr) Or
      (StringReplace(edt_mailsenderadress.Text, ' ', '', [rfReplaceAll]) = EmptyStr) Or
      (StringReplace(edt_mailsendertext.Text, ' ', '', [rfReplaceAll]) = EmptyStr) Or
      (StringReplace(edt_mailrecipient.Text, ' ', '', [rfReplaceAll]) = EmptyStr) Then
   Begin
     fnDisplayMyActionBox('ERR', 'Error', 'Entries are not complete!', EmptyStr, EmptyStr, EmptyStr, True);
     Exit;
   End;

   //Check count of Attachments
   If lstbox_attachments.Count > 10 Then
   Begin
     fnDisplayMyActionBox('ERR', 'Error', 'More than 10 Attachments!', 'Only max. 10 Attachments allowed!', EmptyStr, EmptyStr, True);
     Exit;
   End;

   AttachInfoList := TObjectList.Create;
   Try
     //Load Attachments in Memory Streams
     For i := 0 To lstbox_attachments.Count -1 Do
     Begin
       AttachInfo := TAttachmentInfo.Create;
       AttachInfo.Ms := TMemoryStream.Create;
       try
         AttachInfo.Ms.LoadFromFile(lstbox_Attachments.Items.Strings[i]);
         AttachInfo.Fn := fnGetFileName(lstbox_Attachments.Items.Strings[i]);
         AttachInfoList.Add(AttachInfo);
       Except
         On E:Exception Do
         Begin
           fnDisplayMyActionBox('ERR', 'Error', 'Could not load Attachment into Memory Stream', lstbox_Attachments.Items.Strings[i], E.Message, EmptyStr, True);
         End;
       End;
     End;

     //Insert Test Record into MS SQL Table Mail
     Try
       With (MSSQL_Query1) Do
       Begin
         Active := False;
         SQL.Clear;
         SQL.Add(' Insert Into "' + ModuleUniDBSchema + '.Mail" ');
         SQL.Add(' ( ');
         SQL.Add(' Mail_Project, Mail_Application, Mail_Subject, Mail_SenderAdress, Mail_SenderText, ');
         SQL.Add(' Mail_Recipient, Mail_CC, Mail_Message, Mail_AttachmentCount, Mail_Stati ');

         For i := 0 To lstbox_Attachments.Count -1 Do
         Begin
           SQL.Add(' , Mail_AttachmentName' + IntToStr(i+1));
           SQL.Add(' , Mail_Attachment' + IntToStr(i+1));
         End;

         SQL.Add(' ) ');

         SQL.Add(' Values( ');
         SQL.Add(' :Mail_Project, :Mail_Application, :Mail_Subject, :Mail_SenderAdress, :Mail_SenderText, ');
         SQL.Add(' :Mail_Recipient, :Mail_CC, :Mail_Message, :Mail_AttachmentCount, :Mail_Stati ');

         For i := 0 To lstbox_Attachments.Count -1 Do
         Begin
           SQL.Add(' , :Mail_AttachmentName' + IntToStr(i+1));
           SQL.Add(' , :Mail_Attachment' + IntToStr(i+1));
         End;

         SQL.Add(' ) ');

         ParamByName('Mail_Project').AsString := edt_mailproject.Text;
         ParamByName('Mail_Application').AsString := edt_mailapplication.Text;
         ParamByName('Mail_Subject').AsString := edt_mailsubject.Text;
         ParamByName('Mail_SenderAdress').AsString := edt_mailsenderadress.Text;
         ParamByName('Mail_SenderText').AsString := edt_mailsendertext.Text;
         ParamByName('Mail_Recipient').AsString := edt_mailrecipient.Text;
         ParamByName('Mail_CC').AsString := edt_mailcc.Text;
         ParamByName('Mail_Message').AsString := mem_mailtext.Text;
         ParamByName('Mail_AttachmentCount').AsString := IntToStr(lstbox_attachments.Count);
         ParamByName('Mail_Stati').AsString := '10';

         For i := 0 To lstbox_Attachments.Count -1 Do
         Begin
           ParamByName('Mail_AttachmentName'+IntToStr(i+1)).AsString := TAttachmentInfo(AttachInfoList[i]).fn;
           ParamByName('Mail_Attachment'+IntToStr(i+1)).SetBlobData(TAttachmentInfo(AttachInfoList[i]).ms.Memory, TAttachmentInfo(AttachInfoList[i]).ms.Size);
         End;

         ExecSQL;
       End;
     Except
       On E:Exception Do
       Begin
         fnDisplayMyActionBox('ERR', 'MS SQL Error', 'Could not insert Record into Mail Table!', E.Message, EmptyStr, EmptyStr, True);
       End;
     End;
   Finally
     AttachInfoList.Free;
   End;
end;
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat