关于字符串的引用问题(0分)

  • 主题发起人 主题发起人 cdzerg
  • 开始时间 开始时间
C

cdzerg

Unregistered / Unconfirmed
GUEST, unregistred user!
新建一个这样得AForm,从TForm继承而来,重载它的Create函数如下
constructor Create(AOwner: TComponent
var iReturnValue: String);reintroduce;

然后在另外一个窗口BForm中的某按钮事件函数中,create并且show AForm,cerate的时候
传递一个在BForm中的String,希望在AForm中改变它的值.....但是好像给字符串赋值的时
候就是改变其引用了,所以不成功...如果要用指针因该怎么做?
 
可以再说明白一点吗?
 
你学一个WinAPI中的,在这种情况下多使用PChar类型。
例如:constructor Create(AOwner: TComponent
iReturnValue: PChar);reintroduce;
 
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

/////////////////////////////////////////////
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

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

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
s:='1234';
form2:=TForm2.Create(self,s);
form2.showModal;
form2.free;
showmessage(s);// '567890'
end;

end.

//////////////////////////////////////
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
pS:pointer;
{ Private declarations }
public
constructor Create(AOwner: TComponent
var iReturnValue: String);reintroduce;
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.DFM}

{ TForm2 }

constructor TForm2.Create(AOwner: TComponent
var iReturnValue: String);
begin
inherited create(AOwner);
pS:=@iReturnValue;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
string(pS^):='567890';
end;

end.




 
怎么没分的!
 
Sorry,jsxjd,我提问题得时候,选了50分得,但是我接受问题时,他只给0分积分我选....

怎么给分阿?.....
 
后退
顶部