直接从过程/函数获取TAdvEdit.Text [英] Get TAdvEdit.Text directly from procedure/function

查看:47
本文介绍了直接从过程/函数获取TAdvEdit.Text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我收到错误E2197: [DCC错误] proj1.pas(34):E2197无法将常量对象作为var参数传递:

Hello i get error E2197: [DCC Error] proj1.pas(34): E2197 Constant object cannot be passed as var parameter:

unit proj1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AdvEdit;

type
  TForm1 = class(TForm)
    AdvEdit1: TAdvEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure SetEditText(const instr: string; out outstr: string);
begin
  outstr := instr;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetEditText('Pippo', AdvEdit1.Text);
end;

end.

当然,我可以解决写作问题

Of course, i can solve writing:

procedure TForm1.Button1Click(Sender: TObject);
var sText: string
begin
  SetEditText('Pippo', sText);
  AdvEdit1.Text := sText;
end;

但是当我有许多AdvEdit时,这很难.然后我问,在我的程序中可以直接以TAdvEdit.Text作为参数以某种方式解决问题吗?非常感谢.

But when i have many AdvEdit, then it is hard. Then i ask, is possible solve the problem in some mode giving directly TAdvEdit.Text as parameter in mine procedure? Thanks very much.

推荐答案

我认为 Text 是一个属性.而且您不能将属性传递给 var out 参数.您只能将变量传递给此类参数.

I presume that Text is a property. And you cannot pass a property to a var or out parameter. You can only pass variables to parameters of those kinds.

您需要找到其他方式来编写代码.您已经提出了一个这样的想法,但是对我来说,这似乎不必要地复杂.我没有比这更简单的东西了:

You'll need to find a different way to write your code. You've come up with one such idea, but it seems needlessly complex to me. I cannot see anything simpler than:

AdvEdit1.Text := 'Pippo';

怎么会有比这更简单的代码?您需要至少指定以下内容:

How could there be any code simpler than this? You need to specify at a bare minimum the following:

  • 目标控件.
  • 我们正在处理 Text 属性.
  • 我们正在分配的事实.
  • 新值.

上面的代码可以做到这一点,仅此而已.

The code above does that and nothing more.

这篇关于直接从过程/函数获取TAdvEdit.Text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆