# Remobjects\_OpenXML & threaded TDaMemDataTable opening

**URL:** https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505
**Category:** Data Abstract
**Tags:** oxygene, delphi
**Created:** [November 13, 2020, 2:44pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505 "2020-11-13T14:44:10Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 13, 2020, 2:44pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/1 "2020-11-13T14:44:10Z")

</div>

Hi

_Delphi 10.3.2/RoDA 10.0.0.1481_

I have `Remobjects_OpenXML` defined for my client project which is working well and I do not use the `uROComInit` unit.

I’ve recently tried to convert opening some TDaMemDataTables in a thread using `TTask.Run()`.

Sample code:

```
procedure TPatientData.OpenAsync;
begin
  TTask.Run(
    procedure
    begin
      tbl_Patients.Open; // beforeOpen sets DynamicWhere clause
      tbl_SomeOtherTable.Open; 
      TThread.Synchronize(nil,
        procedure
        begin
          if assigned(AfterOpen) then
            AfterOpen(tbl_Patients); // will call back to the calling UI form
        end
      );
    end
  );
end;

```

The table(s) being opened are always on their own TDataModule which has it’s own Channel & Message components (as well as Bin2DataStreamer and RemoteDataAdapter).

In creating each datamodule instance I set the URL of the Channel and the ClientID of the Message from the main Channel and Message components on my _ClientDataModule_ – so I think I’m right in saying this should make it safe to open the table(s) in a thread.

My problem is that I’ve noticed that I’m getting “CoIniitalize has not been called” errors when trying to open these tables in a thread, even though I have `RemObjects_OpenXML` defined.

I’ve temporarily solved the issue by wrapping the `.open` calls in `CoInitialize`/`CoUninitialize` calls but I’d like to be able to use these business data objects in non-Windows platforms.

How can I fix that so that I don’t need to use `CoInitialize` or `winapi.activex` ?

Thanks

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 13, 2020, 3:02pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/2 "2020-11-13T15:02:01Z")

</div>

Hi,

> [@stuartclennett](#):
>
> How can I fix that so that I don’t need to use `CoInitialize` or `winapi.activex` ?

try to use workaround from this post:

> [@Can't use open/save dialogs on Delphi XE2 in RemObjects VCL Project](https://talk.remobjects.com/t/cant-use-open-save-dialogs-on-delphi-xe2-in-remobjects-vcl-project/1281/8):
>
> you can use this workaround: replace uROComInit with uROInitializedThread in .dpr. add uROInitializedThread.ROInitializeThreads := True; like uses uROInitializedThread, ... {$R \*.res} begin uROInitializedThread.ROInitializeThreads := True; Application.Initialize; ...

it will call `CoInitialize`/`CoUninitialize` by demand on windows platforms only

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 13, 2020, 3:33pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/3 "2020-11-13T15:33:43Z")

</div>

Hi,

> [@EvgenyK](#):
>
> try to use workaround from this post:  
> [Can't use open/save dialogs on Delphi XE2 in RemObjects VCL Project - #8 by EvgenyK](https://talk.remobjects.com/t/cant-use-open-save-dialogs-on-delphi-xe2-in-remobjects-vcl-project/1281/8)  
> it will call `CoInitialize`/`CoUninitialize` by demand on windows platforms only

Did that, and it’s still giving me “CoInitialise has not been called” errors.

I removed the “RemObjects\_OpenXML” directive and re-built, and that made no difference - the error still occurs.

?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 13, 2020, 3:35pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/4 "2020-11-13T15:35:09Z")

</div>

can you check in debugger what exactly code causes “CoInitialise has not been called” error, pls?

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 13, 2020, 3:43pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/5 "2020-11-13T15:43:41Z")

</div>

Hi,

It breaks on line 2724 of `uROMSXML2_TLB` :

```
class function CoDOMDocument60.Create: IXMLDOMDocument3;
begin
  Result := CreateComObject(CLASS_DOMDocument60) as IXMLDOMDocument3;
end;

```

Full call stack: [https://imgur.com/a/gmTIL02](https://imgur.com/a/gmTIL02)

Thanks

_Edit_

If I carry on through the exceptions, I get to this one also:

Exception class EROException with message  
‘Error creating MSXML Document classEOleSysError: CoInitialize has not been called, ClassID: {88D96A05-F192-11D4-A65F-0040963251E5}’.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 13, 2020, 3:46pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/6 "2020-11-13T15:46:36Z")

</div>

you said that the same error was with `RemObjects_OpenXML` too.  
what callstack if `RemObjects_OpenXML` is used?

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 13, 2020, 4:05pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/7 "2020-11-13T16:05:07Z")

</div>

Ok.

So _now_ it’s working. I can’t make it fail again with RemObjects\_OpenXML defined - which I _swear_ it was initially.

I’ll keep testing and reply if I hit any more issues with this.

Thanks

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 13, 2020, 4:07pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/8 "2020-11-13T16:07:31Z")

</div>

> [@stuartclennett](#):
>
> It breaks on line 2724 of `uROMSXML2_TLB` :
> 
> ```auto
> class function CoDOMDocument60.Create: IXMLDOMDocument3;
> begin
> Result := CreateComObject(CLASS_DOMDocument60) as IXMLDOMDocument3;
> end;
> 
> ```

this is as expected:  
`RemObjects_MSXML` requires CoInitialize calls

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 13, 2020, 4:21pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/9 "2020-11-13T16:21:21Z")

</div>

Thanks again Evgeny 🙂

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 16, 2020, 2:41pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/10 "2020-11-16T14:41:56Z")

</div>

Hi Evgeny,

If I _don’t_ define `RemObjects_OpenXML` then should the I use the unit `uROInitializedThread`, or should I use `uROComInit` and call CoInitialize/CoUnInitialize in threads (i.e. `TTask.Run()`) ?

Thanks

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 16, 2020, 2:48pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/11 "2020-11-16T14:48:19Z")

</div>

Hi,

`ROInitializedThread` unit is a workaround when `uROComInit` cannot be used at all.  
for example, std Open/SaveDialogs work incorrectly if `uROComInit` is used…

in other cases `uROComInit` should work correctly

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 16, 2020, 2:54pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/12 "2020-11-16T14:54:18Z")

</div>

> [@EvgenyK](#):
>
> `ROInitializedThread` unit is a workaround when `uROComInit` cannot be used at all.  
> for example, std Open/SaveDialogs work incorrectly if `uROComInit` is used…
> 
> in other cases `uROComInit` should work correctly

I need std Open/Save dialogs to work correctly so I continue to use `ROInitializeThread` ?

Is there anything else I need to know - do I need to call CoInitialize etc in main thread?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 16, 2020, 3:13pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/13 "2020-11-16T15:13:59Z")

</div>

if you are using `ROInitializeThread` solution, you shouldn’t call `CoInitialize` in main thread for correct working of RO SDK.

other code (non RO) may require additional calling of `CoInitialize`

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 16, 2020, 3:31pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/14 "2020-11-16T15:31:37Z")

</div>

Thanks for the clarification Evgeny.

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 24, 2020, 11:23am UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/15 "2020-11-24T11:23:19Z")

</div>

Hi Evgeny,

I’m still hitting an issue with this. I have `uROInitializedThread` in the project source (second below FastMM4).

I am setting `uROInitializedThread.ROInitializeThreads := TRUE` as the first line of project source in the DPR.

I am using `TTask.Run()` to start a process that eventually opens a TDAMemDataTable on a datamodule - and this is still giving me “CoInitialize has not been called” errors when it tries to open the table.

Should I be getting this error or have I misunderstood?

The TDAMemDataTable is on a DataModule that may, or may not, be opened in a thread.

Thanks - I’m a little confused.

Stuart

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 24, 2020, 11:47am UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/16 "2020-11-24T11:47:16Z")

</div>

Hi,

can you create a **simple** testcase that reproduces this behavior, pls?  
you can drop it to support@ for keeping privacy

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 24, 2020, 11:55am UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/17 "2020-11-24T11:55:24Z")

</div>

Hi Evgeny.

I’ll try and find time to do the sample.

Am I right in thinking what I described _should_ work though?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 24, 2020, 12:02pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/18 "2020-11-24T12:02:46Z")

</div>

Hi,

yes, it should work

---

<div class="post-metadata">

### Author: ![stuartclennett](https://talk.remobjects.com/user_avatar/talk.remobjects.com/stuartclennett/32/3000_2.png) [@stuartclennett](https://talk.remobjects.com/u/stuartclennett)
#### Post date: [November 24, 2020, 12:09pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/19 "2020-11-24T12:09:39Z")

</div>

Thanks - that’s helpful.

I’ll try and get a test case, but I have a huge backlog at the moment.

Thank you

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 24, 2020, 12:16pm UTC](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505/20 "2020-11-24T12:16:04Z")

</div>

you may use SOAPMessage, XMLDataStreamer, datXML field(s), DynamicWhere - all may have influence …

[Next page](https://talk.remobjects.com/t/remobjects-openxml-threaded-tdamemdatatable-opening/23505.md?page=2)
