Jump to content

How to inherite a thread safe Class ?


Abaksoft

Recommended Posts

Hi Farshad,

In the same optic of :
http://forums.unigui.com/index.php?/topic/5116-is-a-standard-delphi-unit-thead-safe/?hl=thread+safe

I created a DataModule unit and write there my Class :

Unit scool;
Type Tscool=class(DataModule)

I do this to insure that all my funtions will be thread safe.

Ok, now how can i inherite Tscool from an other thread safe class ?

Can i do some think like:
Type Tscool = Class(TUniversity)
And create only University unit as a DataModule ?

Thx...

Link to comment
Share on other sites

Oh...sorry i did'nt explain well,

 

 

Here is a simple OOP sample, wich describe a classical inhireted classes.

unit Class_Bird;

interface
uses Class_Animal;

type
 TBird=Class(TAnimal)

 private
   fWeight:integer;
   procedure SetWeight(value:integer);

 public
   error:boolean;

   Constructor Create;
   function eat:string; override;

 published
   property Weight:integer read fWeight write SetWeight;
 end;


implementation
{ TAnimal }

function TBird.eat:string;
var str:string;

begin
  // fWeight  in gr
  if fWeight<1000 then
      str:='And I need 50 seeds per day !'
  else if (fWeight>=1000) and (fWeight<2000) then
      str:='And I need 80 seeds per day !'
  else
      str:='And I need 100 seeds per day !';

  result:=inherited + #13+ str;
end;

If i try to write this in an Unigui Thread Safe Unit , the recommended solution is to use UniGui DataModule.

The problem is that I can'nt  inhereted my Class TBird from TAnimal, firstly and from TDataModule on the other hand !

 

type
TBird=Class(TAnimal)           ???

TBird=Class(TDataModule)  ???

 

 

In others words, How can I inhereted a TDataModule Class1 from an other TDataModule Class2  ?

(each class is declared on separate DataModule).

 

Thx...

Animal.zip

Link to comment
Share on other sites

  • Administrators

I analyzed your code. You are using simple classes inherited from TObject. There are not thread-safety considerations with these objects. You dynamically create and destroy them each time  you use them which is OK.

 

Are there any specific things regarding your code which you like to know?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...