Board index » delphi » Multi-tier, multi-thread

Multi-tier, multi-thread

Hello,

I'm new to multi-tier and found something new (to me only) and would like to
get ideas from you experienced guys.

I found a typical client program of those traditional 2-tier client/server
system is usually single threaded only. (unless you change it in purpose)
But I found the client program of 3-tier model is always 2-threaded. Maybe
the compiler generate a auto-created thread for fetching data from apps
server (I guess only).

Also, if I want to access the DM which is initialized from the main thread
from the n th thread (where n >= 2), I'll always get a error. I have to use
the synchronize function to access it thru the main thread but it's really
trouble-some and hard to  code.

So, I tried to create a DM for each thread but I got any error as follow;
    Exception EOleSysError in module xxxxxxxxx
    CoInitialize has not been called.
With the help from some experienced guy, I change the code as follow to
solve the problem but I really don't understand it at all!!

  ...
  OleCheck(CoInitialize(nil));
  try
    {Get the marshalled interface}
    OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IProvider,
    ...
    Synchronize(UpdateUI);
    end;
  finally
    CoUninitialize;
  end;

Is this the only way to solve the problem? It generates n DM with n threads
and take up quite a lot memory (maybe my DM is quite big).

Finally, where I can get some more information about the related topics?

Thanks

Andy Wong

 

Re:Multi-tier, multi-thread


COM Threading is a complex topic. You might want to read through my COM
threading tutorial:
http://www.intac.com/~bly/Programming/Delphi

have fun
--
Binh Ly
http://www.castle.net/~bly/Programming/Delphi

Quote
Andy Wong <an...@post1.com> wrote in message

news:7nacc1$p8e16@forums.borland.com...
Quote
> Hello,

> I'm new to multi-tier and found something new (to me only) and would like
to
> get ideas from you experienced guys.

> I found a typical client program of those traditional 2-tier client/server
> system is usually single threaded only. (unless you change it in purpose)
> But I found the client program of 3-tier model is always 2-threaded. Maybe
> the compiler generate a auto-created thread for fetching data from apps
> server (I guess only).

> Also, if I want to access the DM which is initialized from the main thread
> from the n th thread (where n >= 2), I'll always get a error. I have to
use
> the synchronize function to access it thru the main thread but it's really
> trouble-some and hard to  code.

> So, I tried to create a DM for each thread but I got any error as follow;
>     Exception EOleSysError in module xxxxxxxxx
>     CoInitialize has not been called.
> With the help from some experienced guy, I change the code as follow to
> solve the problem but I really don't understand it at all!!

>   ...
>   OleCheck(CoInitialize(nil));
>   try
>     {Get the marshalled interface}
>     OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IProvider,
>     ...
>     Synchronize(UpdateUI);
>     end;
>   finally
>     CoUninitialize;
>   end;

> Is this the only way to solve the problem? It generates n DM with n
threads
> and take up quite a lot memory (maybe my DM is quite big).

> Finally, where I can get some more information about the related topics?

> Thanks

> Andy Wong

Re:Multi-tier, multi-thread


Thanks Bihn, nice job, appreciate the effort.

Quote
Binh Ly wrote in message <7nj1a1$3m...@forums.borland.com>...
>COM Threading is a complex topic. You might want to read through my COM
>threading tutorial:
>http://www.intac.com/~bly/Programming/Delphi

>have fun
>--
>Binh Ly
>http://www.castle.net/~bly/Programming/Delphi

>Andy Wong <an...@post1.com> wrote in message
>news:7nacc1$p8e16@forums.borland.com...
>> Hello,

>> I'm new to multi-tier and found something new (to me only) and would like
>to
>> get ideas from you experienced guys.

>> I found a typical client program of those traditional 2-tier
client/server
>> system is usually single threaded only. (unless you change it in purpose)
>> But I found the client program of 3-tier model is always 2-threaded.
Maybe
>> the compiler generate a auto-created thread for fetching data from apps
>> server (I guess only).

>> Also, if I want to access the DM which is initialized from the main
thread
>> from the n th thread (where n >= 2), I'll always get a error. I have to
>use
>> the synchronize function to access it thru the main thread but it's
really
>> trouble-some and hard to  code.

>> So, I tried to create a DM for each thread but I got any error as follow;
>>     Exception EOleSysError in module xxxxxxxxx
>>     CoInitialize has not been called.
>> With the help from some experienced guy, I change the code as follow to
>> solve the problem but I really don't understand it at all!!

>>   ...
>>   OleCheck(CoInitialize(nil));
>>   try
>>     {Get the marshalled interface}
>>     OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IProvider,
>>     ...
>>     Synchronize(UpdateUI);
>>     end;
>>   finally
>>     CoUninitialize;
>>   end;

>> Is this the only way to solve the problem? It generates n DM with n
>threads
>> and take up quite a lot memory (maybe my DM is quite big).

>> Finally, where I can get some more information about the related topics?

>> Thanks

>> Andy Wong

Other Threads