Question : DBGrid's content into email

Hi,

I have one dataset with data on my form created the following way:
->a DBGrid1 on myform with property DataSource set to DataSource1.
->a DataSource1 with property DataSet set to ClientDataset1
->a ClientDataSet with property ProviderName set to XMLTransformProvider1.
    and property Active to True.
->a XMLTransformProvider1 with the property FileName set to a xml-filename.
->and a DBNavigator with the propery DataSource set to DataSource1.
->and I have set the 3 columns:'dt','tm' and 'val' (dt=date,tm=time,and val=value)
    as persistend fields in the DBGrid.

Now I have made a button that opens a standard email client. That I have put
in the code-section. But I need the dbgrid's content copied to the body-section
of the email. Who knows the answer and is willing to help me?

Greetings, Peter Kiers
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TMainForm.Button1Click(Sender: TObject);
var
  strEmail, strSubject, strBody, Param: string;
begin
  strEmail := '[email protected]';
  strSubject := 'Your Subject';
  strBody := 'Your Message Text';

  Param := 'mailto:' + strEmail + '?subject=' + strSubject +
           '&Body=' + strBody;

  ShellExecute(MainForm.Handle, 'open', PChar(Param), nil, nil, SW_SHOWNORMAL);
end;

Answer : DBGrid's content into email

you can use  Geert_Gruwez's or Epasquier's functions, but I guess it will fail on ShellExecute function, because of too much character and special characters.

As far as I know you've installed JCL -> you can use its JclMAPI unit like this:

uses
  JclMAPI;

procedure TForm1.Button1Click(Sender: TObject);
var
  strEmail, strSubject: string;
  s: string;
  i: Integer;
begin
  strEmail := '[email protected]';
  strSubject := 'Your Subject';

  // use Geert_Gruwez's function or Epasquier's function to generate body
  s := '';
  for I := 0 to table.Fields.Count-1 do
    s := s + Format('%20:20s', [table.Fields.Fields[I].Caption]);
  s := s + #13#10 + DupeString('-', 21*table.Fields.Count) + #13#10;
  while not table.Eof do
  begin
    for I := 0 to table.Fields.Count-1 do
      s := s + Format('%20:20s', [table.fields.Fields[I].AsString]);
    s := s + #13#10;
    table.Next;
  end;

  JclSimpleSendMail(strEmail, '', strSubject, s );
end;
Random Solutions  
 
programming4us programming4us