IT_ZZW035 发表于 2014-3-25 16:59:46

swap 交换

EDIT1.TEXT:='1';
EDIT2.TEXT:='2';
SWAP后应该是
EDIT1.TEXT:='2'
EDIT2.TEXT:='1'
根据给的源码结果总是
EDIT1.TEXT:='2'
EDIT2.TEXT:='2'
求解
源码如下 :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Swap_fun(var str_a:String; str_b:String);
private
    { Private declarations }
public
    { Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
str1: String;
str2: String;
temp: String;
begin
str1:= Edit1.Text;
str2:= Edit2.Text;
Swap_fun(str1, str2);
Edit1.Text:= str1;
Edit2.Text:= str2;
end;
procedure tform1.Swap_fun(var str_a:String;str_b:String);
var
temp:string;
begin
temp:= str_a;
str_a:= str_b;
str_b:= temp;
end;
end.


comeheres 发表于 2014-3-25 19:41:05

提问请发悬赏贴
暂时不给你答案,自己看下下面的知识点






bj584767285 发表于 2014-3-25 20:15:07

支持一下!

tlwangxd 发表于 2014-10-23 07:10:25

每二个参数引用前边没有加VAR,或这样写:Var str_a ,str_b:String
页: [1]
查看完整版本: swap 交换