将公共方法添加到您的聊天表单。
with TChatForm.Create(Application) do
begin
PassUserName(FUsername);
Show;
end;
procedure TChatForm.PassUserName(const aUsername: string);
begin
Caption := 'You can now chat: '+ aUsername;
end;
这允许您将任何您想要的内容传递到您的聊天表单中,而无需通过简单地添加新方法来更改现有的公共方法。
不使用“with”或 FUsername 来解决问题的示例:
frmChat := TChatForm.Create(Application);
frmChat.Nickname := aUsername;
frmChat.Show;
TChatForm = class(TForm)
private
FUsername : string;
procedure SetNickName(const Value: string);
function GetNickName: string;
public
property NickName: string read GetNickName write SetNickName;
end;
procedure TChatForm.SetNickName(const Value: string);
begin
FUsername := Value;
end;
function TChatForm.GetNickName: string;
begin
Result := FUsername;
end;