小编Emr*_*men的帖子

在不使用变量的情况下在“with”语句中创建对象

var 
  UserName, NickName, UserID: string;
begin
  with TStringList.Create do
  begin
    CommaText := 'ali,veli,4950';
    UserName := x[0];  //what is x ? (x is Tstringlist.create)
    NickName := x[1];
    UserID := x[2];
  end;   
end;
Run Code Online (Sandbox Code Playgroud)

如果我使用下面的代码,它就可以工作。但我不想声明一个变量。我可以将它与任何变量一起使用吗?

with声明中,我如何使用它?

var 
  tsl: TStringList;
begin
  tsl := TStringlist.Create;
  with tsl do
  begin
    CommaText := 'ali,veli,4950';
    UserName := tsl[0]; 
    NickName := tsl[1];
    UserID := tsl[2];
  end;
end;
Run Code Online (Sandbox Code Playgroud)

delphi variables with-statement declare

1
推荐指数
1
解决办法
109
查看次数

标签 统计

declare ×1

delphi ×1

variables ×1

with-statement ×1