如何直接获取实参的变量名?
delphi吧
全部回复
仅看楼主
level 8
比如
procedure addXY(x, y :Integer);
begin
showmessage(inttostr(x) + inttostr(y) + '=' + inttostr(add(x, y)));
end;
调用时
a := 1;
b := 2;
addXY(a, b);
弹窗时能显示 a + b = 3
而不是 1 + 2 = 3
2017年09月02日 17点09分 1
level 8
上面不严谨,补充一下 showmessage(inttostr(x) + ' + ' + inttostr(y) + ' = ' + inttostr(add(x, y)))
2017年09月03日 07点09分 2
吧务
level 14
用值参,自己传个字符串进去呗。
2017年09月04日 01点09分 3
那要传两次参数,我想实现一次就ok的。这个可以吗?
2017年09月04日 01点09分
回复
QQ_2286363096
:应该不可以
2017年09月04日 11点09分
@BambooCaep 好吧,打消这个念头!
2017年09月04日 12点09分
level 8
不行 编译运行时只有地址
2017年09月05日 04点09分 4
level 3
procedure addXY(x, y :Integer);
var a,b:integer;
begin
a:=x;
b:=y;
showmessage(inttostr(a) + inttostr(b) + '=' + inttostr(add(x, y)));
end;
2017年09月13日 08点09分 5
一看就像大侠,这是递归吗?可是这段代码我试了不能编译,为什么呢?
2017年09月13日 10点09分
回复
QQ_2286363096
:该传整型值传了个过程进去,编译过了才见鬼呢!
2017年09月13日 13点09分
level 3
yc515623878,你提供的程序,我在delphi2007里,编译运行后,结果就是1+2=3,没有问题呀
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure addXY(x, y :Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var a,b:integer;
begin
a:=1;
b:=2;
addxy(a,b);
end;
procedure TForm1.addXY(x, y :Integer);
begin
showmessage(inttostr(x) +'+'+ inttostr(y) + '=' + inttostr(x+y));
end;
end.
2017年09月15日 12点09分 6
我想让它显示 为a+b=3 这样的!
2017年09月15日 12点09分
level 3
确实不能直接一次传过去。不过,可以用一个方法代替一下。
showmessage('a+b=' + inttostr(x+y));
2017年09月16日 06点09分 7
level 8
看来只能用哈希表传址才可以,但是有时候不见得会用哈希表,这点比较麻烦。
2017年09月20日 13点09分 8
不传址就要用全局哈希变量
2017年09月20日 13点09分
level 1
type data=record
a:integer;
name:='a';
end;
2017年10月26日 09点10分 9
1