Outlook adxForm repaint or refresh on incoming email like on switching folders

Add-in Express™ Support Service
That's what is more important than anything else

Outlook adxForm repaint or refresh on incoming email like on switching folders
 
MirkoB


Guest


Hello,

I am still working on my phone notes plugin for practice.
So what I do now is the following:
1. checking for incoming email having a certain subject as described in this topic.
https://www.add-in-express.com/forum/read.php?FID=1&TID=411
2. when the ceratin subject is found I add a dataset to a database and would like to reload a content of the table sitting on my adxForm inside a TPageControl.

Checking the incoming emails for a certain topic works perfectly and reloading the content of the table as well.

The problem is, that the "update" of the table is not shown. It looks as if I still got the table in a state before reloading its content.
When I switch to another folder, I get it with the correct amount of lines loaded from the database.

Switching back to the inicial folder gives me the old, not updated view.

Best regards

Mirko
Posted 09 Apr, 2019 06:35:46 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Mirko,

What you do for the table on the pane to get updated?


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2019 06:50:23 Top
MirkoB


Guest


Hi Andrei,

I just reload the datasets. I don't repaint the control or anything.
When I use a button on the pane to fire the update procedure below it works perfectly.

Best regards

Mirko


NOTESQUERY.Close;
  NOTESQUERY.SQL.Text := 'SELECT * from notestable LEFT JOIN notes_assign ON NT_ID = NA_NOTESID WHERE NA_USER = ''' + windowsuser + ''' AND NA_STATUS = 0 ORDER BY NT_LASTEDITED Desc;';
  NOTESQUERY.Execute;

  NOTESGRID.RowCount := 2;
  NOTESGRID.ClearRows(1,1);
  while not NOTESQUERY.Eof do
  begin
    if NOTESGRID.Cells[0, 1] <> '' then
      NOTESGRID.AddRow;
    NOTESGRID.Cells[0,NOTESGRID.RowCount-1] := DateTimetoStr(UnixtoDateTime(NOTESQUERY.FieldbyName('NT_LASTEDITED').AsInteger));
    NOTESGRID.Cells[1,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_NAME').AsString;
    NOTESGRID.Cells[2,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_TELEPHONE').AsString;
    NOTESGRID.Cells[3,NOTESGRID.RowCount-1] := '';
      if NOTESQUERY.FieldbyName('NT_MESSAGE').AsString <> '' then
        NOTESGRID.AddButton(4,NOTESGRID.RowCount-1,48,18,'??????',hacenter,vacenter);
      NOTESGRID.AddCheckBox(6,NOTESGRID.RowCount-1,false,True);
      NOTESGRID.Cells[7,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_ID').AsString;
      NOTESGRID.Cells[8,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_PRIORITY').AsString;
    NOTESQUERY.Next;
  end;
Posted 09 Apr, 2019 07:01:12 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
I assume that code fragment belongs to the code of the pane (not to the code of the add-in module) and NOTESGRID is a reference to the grid on that pane. Is my assumption correct?


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2019 07:08:19 Top
MirkoB


Guest


This fragement is a procedure I call from the doadditem procedure when checking an incoming email.
I added a TadxForm (and the Grid Control inside the pane) and in this TadxForm I got the procedure for updating the grid (the code fragment from above) .


procedure TAddInModule.DoItemAdd(ASender: TObject; const Item: IDispatch);
var
  IMail: MailItem;
begin
  if Assigned(Item) then begin
    Item.QueryInterface(IID__MailItem, IMail);
    if Assigned(IMail) then
      try
        if IMail.UnRead then begin
          if ContainsText(IMail.Subject,'Phone Note') = True then
          begin
            adxPhoneNotes.fillnotesgrid();
          end;
        end;
      finally
        IMail := nil;
      end;
  end;
end;



procedure TadxPhoneNotes.fillnotesgrid();
var xaction : String;
begin
  NOTESQUERY.Close;
  NOTESQUERY.SQL.Text := 'SELECT * from notestable LEFT JOIN notes_assign ON NT_ID = NA_NOTESID WHERE NA_USER = ''' + windowsuser + ''' AND NA_STATUS = 0 ORDER BY NT_LASTEDITED Desc;';
  NOTESQUERY.Execute;

  NOTESGRID.RowCount := 2;
  NOTESGRID.ClearRows(1,1);
  while not NOTESQUERY.Eof do
  begin
    if NOTESGRID.Cells[0, 1] <> '' then
      NOTESGRID.AddRow;
      NOTESGRID.Cells[0,NOTESGRID.RowCount-1] := DateTimetoStr(UnixtoDateTime(NOTESQUERY.FieldbyName('NT_LASTEDITED').AsInteger));
      NOTESGRID.Cells[1,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_NAME').AsString;
      NOTESGRID.Cells[2,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_TELEPHONE').AsString;
      NOTESGRID.Cells[3,NOTESGRID.RowCount-1] := '';
      if NOTESQUERY.FieldbyName('NT_MESSAGE').AsString <> '' then
        NOTESGRID.AddButton(4,NOTESGRID.RowCount-1,48,18,'??????',hacenter,vacenter);
      NOTESGRID.AddCheckBox(6,NOTESGRID.RowCount-1,false,True);
      NOTESGRID.Cells[7,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_ID').AsString;
      NOTESGRID.Cells[8,NOTESGRID.RowCount-1] := NOTESQUERY.FieldbyName('NT_PRIORITY').AsString;
    NOTESQUERY.Next;
  end;
end;


Best regards...

Mirko
Posted 09 Apr, 2019 07:17:13 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Mirko,

It looks like you cache adxPhoneNotes. Try to get a new reference instead. Does this solve the issue?


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2019 08:06:51 Top
MirkoB


Guest


No I'm sorry.
In the adxOlFormsManager1.Items[0] Cached is already set to csNewInstanceForEachFolder;

Best regards...

Mirko
Posted 09 Apr, 2019 08:12:21 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
This isn't what I meant. How do you set adxPhoneNotes?


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2019 08:23:36 Top
MirkoB


Guest


I just created it from the menue and added it in the outlook forms manager as item.
I set the explorer layout to elDockRight and it was showing up directly after starting outlook.
But I think caching is a good approach because when I set Cached to csOneInstanceForAllFolders I dont get an update at all, even when I switch to another folder.

Best regards

Mirko
Posted 09 Apr, 2019 08:50:12 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
I see.

At the design time you create a TadxOlFormsCollectionItem. Such an item lets you specify the name of the form class as well as the region (ExplorerLayout & InspectorLayout) in which instances of that form class will be created and shown.

In the event procedure handling the ItemAdd event, you are expected to get the form instance currently shown and invoke the fillnotesgrid() method on it.

I suppose you store adxPhoneNotes in your code and because of this you call fillnotesgrid() on a wrong form instance. To work around this, you need to get the form instance currently shown.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2019 09:05:25 Top