Board index » cppbuilder » Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

Re: How to access to properties (e.g. TLabel::Caption) inside a thread?


2006-09-01 02:22:20 AM
cppbuilder18
<MR>wrote:
Quote

[...] Is there are real reason to stop this behaviour
(or 'just' convention). I never run into conflict with this.
When could such a conflict occur? Would it be acceptable to
use two preeceeding underscores?
I can't answer you because I WOULD NEVER DO IT! Ergo, I
wouldn't know! ;-)
~ JD
 
 

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

<MR>wrote:
Quote

[...] Did I something wrong?
If you look at the sample that I posted you should notice that
these lines are different:
Quote
bool get_is_done(void);
void set_is_done(bool _val);
They're missing __fastcall - ie:
bool __fastcall get_is_done(void);
and while I'm not convinced that __fastcall is needed,
certainly the setters and getters must be prototyped
*before* they're used - ie:
private:
bool __fastcall get_is_done(void);
void __fastcall set_is_done(bool _val);
public:
__property bool is_done={ read=get_is_done, write=set_is_done };
Quote
void TThreadCopyFile::set_is_done(bool _val) {
void __fastcall TThreadCopyFile::set_is_done(bool _val) {
Quote
It can't be that accessing properties itself is not allowed
within a thread,
No. There was nothing wrong with what you posted except as I
noted.
~ JD
 

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

"JD" < XXXX@XXXXX.COM >schrieb:
Quote
I strongly object to defining function bodies in the body of
the class like this. Prototype in the class definition and
put all of the code in one place but this would cause you
problems because you're not making these functions members of
the class.
but this would cause you
problems because you're not making these functions members of
the class.
Sorry, I didn't understand. I've always thought there is no difference
(beside readability) and I never run into conflict with this
assumption. What is the problem doing so?
Thanks,
Michael
 

{smallsort}

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

Huuh, I found the problem:
I made some kind of recursive call in the property access:
__property bool is_done={
read=get_is_done,
write=set_is_done
};
bool get_is_done(void);
void set_is_done(bool _val);
void TThreadCopyFile::set_is_done(bool _val) {
critical_section->Acquire();
is_done=_val; // ERROR-LINE
critical_section->Release();
}
Replacing the ERROR-LINE with
val_is_done=_val;
after having defined
bool val_is_done;
works fine.
Defining the property getter/setter-methods before the assignment
inside the __property definitions seems to make no difference (perhaps
only necessary in Delphi (or older versions of BCB)?)
Thanks,
Michael
 

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

<MR>wrote:
Quote

>but this would cause you problems because you're not making
>these functions members of the class.

Sorry, I didn't understand.
If they're not members of the class, they end up in the global
name space.
Quote
and I never run into conflict with this assumption. What is
the problem doing so?
Sooner or later you'll get a job where there is tons of legacy
code and libs that you'll have to work with. Your #1 priority
will be to encapsulate and isolate your code from all the
other. Name spaces help but IMO they're often misused and only
cause more issues when all you need do is encapsulate (make it
part of the class).
~ JD
 

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

"JD" < XXXX@XXXXX.COM >schrieb:
Quote

<MR>wrote:
>
>>but this would cause you problems because you're not making
>>these functions members of the class.
>
>Sorry, I didn't understand.

If they're not members of the class, they end up in the global
name space.
Hmmm...
am I right, we are discussing e.g.
class my_class {
void my_fct() {
..
};
};
versus
class my_class {
void my_fct();
};
void my_class::my_fct() {
...
}
?
No members? I.e. they are accessible like members (in the source-code,
e.g.
class my_class c;
c.my_fct();
), but are stored inside the obj-files in a different way?
Quote

>and I never run into conflict with this assumption. What is
>the problem doing so?

Sooner or later you'll get a job where there is tons of legacy
code and libs that you'll have to work with. Your #1 priority
will be to encapsulate and isolate your code from all the
other. Name spaces help but IMO they're often misused and only
cause more issues when all you need do is encapsulate (make it
part of the class).
I am quite astonished...
At first thought, I could not see any reason, why this is that way you
described, i.e. why should this been implemented this way...
At second thought I got the idea, this might be necessary, because
normally the class-declarations are done inside the .h-file and so are
included from potentiall many modules.
Is there any reference to that issue?
Thanks,
Michael
 

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

<MR>wrote:
Quote

At first thought, I could not see any reason, why this is
that way you described, i.e. why should this been
implemented this way...

At second thought I got the idea, this might be necessary,
because normally the class-declarations are done inside
the .h-file and so are included from potentiall many modules.

Is there any reference to that issue?
The truth is that I speak only from my experiance. Moving
into a big shop forced me to change the way I coded because
of problems with my code that was just like yours is.
I once knew (for about 10 minutes) exactly what was happening
but there was no reason to remember the details - just to not
to do that that way and that was good enough for me.
I've only been working with C++ and Windows for about 4 years
and there is sooo much that I have yet to learn v/s what I do
know.
~ JD
 

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

<MR>wrote:
Quote

I made some kind of recursive call in the property access:

is_done=_val; // ERROR-LINE
Setting the property causes the properties setter method to be
called where you're setting the property which causes the
setter method to be called ect. ect. ect.. I missed that but
I had it in my sample.
Quote
Replacing the ERROR-LINE with
val_is_done=_val;
after having defined
bool val_is_done;
works fine.
That is how properties work.
~ JD
 

Re:Re: How to access to properties (e.g. TLabel::Caption) inside a thread?

Quote
The truth is that I speak only from my experiance. Moving
into a big shop forced me to change the way I coded because
of problems with my code that was just like yours is.
I once knew (for about 10 minutes) exactly what was happening
but there was no reason to remember the details - just to not
to do that that way and that was good enough for me.

I've only been working with C++ and Windows for about 4 years
and there is sooo much that I have yet to learn v/s what I do
know.
Ok, thanks a lot. I'll keep this in mind, but for smaller projects I
suppose I'm using my methode at first, because it is much more
readable, because the whole class is together. If the class is used
for more projects I'll move the bodies in the .cpp-file.
Quote
I've only been working with C++ and Windows for about 4 years
and there is sooo much that I have yet to learn v/s what I do
know.
That's true. You are never ready...
Thanks,
Michael