C
cqwty
Unregistered / Unconfirmed
GUEST, unregistred user!
用了delphi这么长时间,但是对这个工具还是不熟悉。我想问一下,当拖控件放在窗体上的时候,这个控件名称是怎么实现自动的?比如说我拖5个button在窗体上,这5个窗体的名字就分别是button1,button2,button3,button3,button5,那么在delphi里面是怎么实现的呢?我查了一下tcomponent里面的Name属性的实现代码,没有发现什么踪迹。这段代码是:
constructor TComponent.Create(AOwner: TComponent);
begin
FComponentStyle := [csInheritable];
if AOwner <> nil then AOwner.InsertComponent(Self);
end;
procedure TComponent.InsertComponent(AComponent: TComponent);
begin
AComponent.ValidateContainer(Self);
ValidateRename(AComponent, '', AComponent.FName);
Insert(AComponent);
AComponent.SetReference(True);
if csDesigning in ComponentState then
AComponent.SetDesigning(True);
Notification(AComponent, opInsert);
end;
procedure TComponent.ValidateRename(AComponent: TComponent;
const CurName, NewName: string);
begin
if (AComponent <> nil) and not SameText(CurName, NewName) and
(AComponent.Owner = Self) and (FindComponent(NewName) <> nil) then
raise EComponentError.CreateResFmt(@SDuplicateName, [NewName]);
if (csDesigning in ComponentState) and (Owner <> nil) then
Owner.ValidateRename(AComponent, CurName, NewName);
end;
这是相关的代码,可是看不出来是从哪里来这么设置所创建的控件的名字的了。
各位高手请发表看法了。
constructor TComponent.Create(AOwner: TComponent);
begin
FComponentStyle := [csInheritable];
if AOwner <> nil then AOwner.InsertComponent(Self);
end;
procedure TComponent.InsertComponent(AComponent: TComponent);
begin
AComponent.ValidateContainer(Self);
ValidateRename(AComponent, '', AComponent.FName);
Insert(AComponent);
AComponent.SetReference(True);
if csDesigning in ComponentState then
AComponent.SetDesigning(True);
Notification(AComponent, opInsert);
end;
procedure TComponent.ValidateRename(AComponent: TComponent;
const CurName, NewName: string);
begin
if (AComponent <> nil) and not SameText(CurName, NewName) and
(AComponent.Owner = Self) and (FindComponent(NewName) <> nil) then
raise EComponentError.CreateResFmt(@SDuplicateName, [NewName]);
if (csDesigning in ComponentState) and (Owner <> nil) then
Owner.ValidateRename(AComponent, CurName, NewName);
end;
这是相关的代码,可是看不出来是从哪里来这么设置所创建的控件的名字的了。
各位高手请发表看法了。