BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cannot find the mistake in this code

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing
View previous topic :: View next topic  
Author Message
Thomas Fuchs
Guest





PostPosted: Wed Oct 22, 2003 6:52 pm    Post subject: Cannot find the mistake in this code Reply with quote



Hi,

I'm desperate! I'm new to writing components and just wanted to start very
simple with a panel which becomes red if the mouse moves over it (I know I'd
better catch the WM_MOUSEENTER message for this but this doesn't matter
here) AND if the panel's "Bla"-property = True.
But nothing happens. If I set Bla to True during design time, it's false
during runtime.
What's wrong here? Perhaps it's just a small mistake but I can't find it and
I searched for hours!

==================
unit Test;

interface

uses
SysUtils, Classes, Controls, ExtCtrls, Forms, Graphics, Windows, Messages;

type
TTEST = class(TPanel)
private
Fbla: Boolean;
public
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
published
property Bla: Boolean read Fbla write Fbla default True;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Desperate research', [TTEST]);
end;

procedure TTEST.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);

if Fbla then
color := clred;
end;

end.


==========
Thank you!


Back to top
Paul van Kan
Guest





PostPosted: Wed Oct 22, 2003 7:50 pm    Post subject: Re: Cannot find the mistake in this code Reply with quote



From the D7 Helpfile (topic Default property values):

<quote>
Note

Declaring a default value does not set the property to that value. The
component's constructor method should initialize property values when
appropriate. However, since objects always initialize their fields to 0, it
is not strictly necessary for the constructor to set integer properties to
0, string properties to null, or Boolean properties to False.

</quote>

constructor TTEST.Create(AOwner: TComponent)
begin
inherited Create(AOwner);
FBla := True;
end;

Good luck,

Paul

"Thomas Fuchs" <tommifuchs (AT) gmx (DOT) de> schreef in bericht
news:bn6jjb$l8j$01$1 (AT) news (DOT) t-online.com...
Quote:
Hi,

I'm desperate! I'm new to writing components and just wanted to start very
simple with a panel which becomes red if the mouse moves over it (I know
I'd
better catch the WM_MOUSEENTER message for this but this doesn't matter
here) AND if the panel's "Bla"-property = True.
But nothing happens. If I set Bla to True during design time, it's false
during runtime.
What's wrong here? Perhaps it's just a small mistake but I can't find it
and
I searched for hours!

==================
unit Test;

interface

uses
SysUtils, Classes, Controls, ExtCtrls, Forms, Graphics, Windows,
Messages;

type
TTEST = class(TPanel)
private
Fbla: Boolean;
public
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
published
property Bla: Boolean read Fbla write Fbla default True;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Desperate research', [TTEST]);
end;

procedure TTEST.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);

if Fbla then
color := clred;
end;

end.


==========
Thank you!





Back to top
Rob Kennedy
Guest





PostPosted: Wed Oct 22, 2003 7:53 pm    Post subject: Re: Cannot find the mistake in this code Reply with quote



Thomas Fuchs wrote:
Quote:
If I set Bla to True during design time, it's false
during runtime.
[...]
property Bla: Boolean read Fbla write Fbla default True;

The "default" directive tells the streaming system that if the property
is set to True as design time, that property's value should not be
stored in the DFM file.

When a new instance of TTest is created, all fields are set to 0, which
means that the initial value of the FBla field will be False. Since
there is no entry in the DFM file for the Bla property, that property
won't be changed from its initial value. That's why the Bla property is
False at run time.

If you include a "default" value for a property, you need to set that
value in the control's constructor:

constructor TTest.Create(AOwner: TComponent);
begin
inherited;
FBla := True;
end;

--
Rob


Back to top
Brian Cook
Guest





PostPosted: Wed Oct 22, 2003 8:42 pm    Post subject: Re: Cannot find the mistake in this code Reply with quote

Quote:
Hi,

Greetings.


Quote:
I'm desperate!

Aren't we all.


Quote:
What's wrong here? Perhaps it's just a small mistake but I can't find it and
I searched for hours!

Fbla needs to be initialized...


Quote:
type
TTEST = class(TPanel)
private
Fbla: Boolean;
public

constructor Create( AOwner: TComponent ); override;

Quote:
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
published
property Bla: Boolean read Fbla write Fbla default True;
end;

implementation

constructor TTEST.Create( AOwner: TComponent );
begin
inherited Create( AOwner );
Fbla := True;
end;


Good luck, Brian

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.