Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2008, 08:32 AM
Marky3 Marky3 is offline
Member
 
Join Date: Feb 2005
Posts: 65
Default tfont within custom component

I have written a custom component derived from the TComponent class where I am using a TFont component.
The code looks something like this:-

class = TCustomComp(TComponent)
private
FFont: TFont; // declare instance of TFont
procedure setFont(Value: const); // setter procedure
''
''


published
property Font: TFont read FFont write setFont;
''
''
end;

TCustComp.Create(AOwner: TComponent);
begin
inherited Create(AOwner: TComponent);
FFont:=TFont.Create; // Create FFont
end;


procedure TCustComp.setFont(Value: Const);
begin
FFont.Assign(Value);
end;


The program compiles and runs ok. But if I change any value of TFont in the object inspector when using the component I always get an error message warning of illegal access of memory or something along those lines. What am I doing wrong?









Mark Green
Reply With Quote
  #2  
Old 09-19-2008, 12:27 AM
mshkolnik mshkolnik is offline
Senior Member
 
Join Date: Jul 2001
Posts: 4,195
Default RE: tfont within custom component

The code you posted is correct. The error is in some another code. Just post the full unit.

With best regards, Mike Shkolnik
http://www.scalabium.com
Reply With Quote
  #3  
Old 09-19-2008, 02:20 AM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: tfont within custom component

[pre]
You don't really need the setter method.

[/pre][DELPHI]
class = TCustomComp(TComponent)
private
FFont: TFont; // declare instance of TFont
procedure FFontOnChange(Sender: TObject);
public
constructor Create(AOwner: TComponent);
destructor Destroy; override;
published
property Font: TFont read FFont write FFont;
end;

constructor TCustComp.Create(AOwner: TComponent);
begin
inherited Create(AOwner: TComponent);
FFont:=TFont.Create; // Create FFont
FFont.OnChange := FFontOnChange;
end;

destructor TCustComp.Destroy; //override;
begin
FFont.Free;
inherited;
end;

procedure TCustComp.FFontOnChange(Sender: TObject);
begin
Refresh;
end;
[/DELPHI][pre]
"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams
[/pre]

Chris
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:34 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.