Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the name property of a new component

Status
Not open for further replies.

Robertio

Programmer
Oct 9, 2000
87
GB
Hopefully something simple I'm missing

We have our own components that are inherited from existing compenents, with the properties changed to our internal standards.

Ideally the component names would be prefixed with our company standards for them (save a bit of typing), unfortunately this is not quite working.

Have tried:

private
FName: TComponentName;
protected
procedure SetName(const NewName: TComponentName);override;
public
published
property Name : TComponentName read FName write SetName;

then the SetName:

const
ucstd = 'abc';

procedure TheComponent.SetName(const NewName: TComponentName);
begin
inherited;
if copy(NewName,1,3) <> ucstd then
Name := ucstd + NewName;
end;

This sets the name in the code correctly, but the property in the object inspector is blank, if we set FName rather than name it works in reverse. If we do both it hangs or access violates.

Any ideas?
 
You want to set the default name property to a compoany standard so you don't have to keep typing it manually, is this correct? If so, I remember reading there's a keyword for it. I don't have a lot of time now, so I'll look for it later and post again.
 
Hi
I don't think 'default' is relevant in this case and it may be the case that 'default' only works for ordinal values, so you can't have a default string.

As you are saying you need to read and write the new name to reflect the changes correctly.

I think it may be difficult to get an active object to rename itself in this way.

Steve..

 
Oops, I misread your question, I was in a hurry this morning.

I may be wrong, since you say you can get it to work, but it seems to me that setting the Name property inside the SetName method would lead to infinite recursion as SetName will continually be called. Personally, I would set the fName variable.

I don't really see any problem with the code if you use fName. By 'it works in reverse' do you mean that if you use fName it has an incorrect string?
 
If I use FName it sets the name property in the object inspector to the intended value, however, the name value for the form in the code does not get changed.

It is very strange.

You are right, it would recursively call itself, except the if statement gets run first. When it enters for the second time it finds the first 3 characters to be the same as the constant so does not try to recall setname.

I'm sure we'll get to the bottom of it eventually, we are supposed to be switching over to Delphi 6 shortly (5 at the moment) and it will probably deal with it differently anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top