这个问题不知道怎么转换了! pp:=TFileReco(vv); Ti:=^pp;出错!该怎么写啊!多谢了!unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TFileReco = Record
SFileName, SFileFullName : String;
FileSize : Integer;
FileAttrib : Integer;
FileDateTime : TFileTime;
IsDir : Boolean;
end; TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function huabo(ss:pointer):boolean;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var Ti:^TFileReco;
vv:pointer;//variant
pp:TFileReco;begin
huabo(vv); pp:=TFileReco(vv);
Ti:=^pp; showmessage(pchar(@ti.SFileName));end;function TForm1.huabo(ss: pointer): boolean;
var aa:TFileReco;
bb:^pointer;
begin
aa.SFileName:='adfajsfjasdf';
ss:=@aa;
result:=true;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TFileReco = Record
SFileName, SFileFullName : String;
FileSize : Integer;
FileAttrib : Integer;
FileDateTime : TFileTime;
IsDir : Boolean;
end; TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function huabo(ss:pointer):boolean;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var Ti:^TFileReco;
vv:pointer;//variant
pp:TFileReco;begin
huabo(vv); pp:=TFileReco(vv);
Ti:=^pp; showmessage(pchar(@ti.SFileName));end;function TForm1.huabo(ss: pointer): boolean;
var aa:TFileReco;
bb:^pointer;
begin
aa.SFileName:='adfajsfjasdf';
ss:=@aa;
result:=true;
end;end.
你必须在huabo中建立一个。
aa:=TFileReco.Create;
aa.SFileName:='adfajsfjasdf';
ss:=@aa;
result:=true;
我直接改为了:Ti:=^TFileReco(vv);错误提示为:[Error] Unit1.pas(43): Incompatible types: 'Char' and 'Pointer'
请问要怎么转换?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
PFileReco = ^TFileReco;
TFileReco = Record
SFileName, SFileFullName : String;
FileSize : Integer;
FileAttrib : Integer;
FileDateTime : TFileTime;
IsDir : Boolean;
end;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function huabo(var ss:pointer):boolean;
end;var
Form1: TForm1;implementation{$R *.dfm}
var aa:TFileReco;
function TForm1.huabo(var ss: pointer): boolean;
begin
aa.SFileName:='adfajsfjasdf';
ss:=@aa;
result:=true;
end;procedure TForm1.Button1Click(Sender: TObject);
var Ti:PFileReco;
vv:pointer;//variant
pp:TFileReco;begin
huabo(vv); Ti :=PFileReco(vv); ShowMessage(Ti.SFileName);// pp:=vv);
// Ti:=^pp;// showmessage(pchar(^vv.SFileName));end;
end.
function TForm1.huabo(ss: pointer): boolean;
var aa:^TFileReco;begin
aa:=ss;
aa^.SFileName:='adfajsfjasdf';
// ss:=@aa;
result:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Ti:^TFileReco;
VV:pointer;//variant
pp:TFileReco;
begin huabo(@pp);
// pp:=TFileReco(vv);
// ti:=vv;
// Ti:=@pp;
showmessage(pchar(pp.SFileName));
end;
你的代码可以执行,没乱码,但不晓得是不是不适合我原来的思路!
我是做个程序配合vc中的viod **name 就是两重指针,并且类型是不定的!
把乱码搞定就好了!
据说vv要开辟内存 既 GetMem(vv,SizeOf(TFileReco));
但开辟了,还是乱码,虽然乱码形式变了,呵呵!请教啊!
程序在跟踪编译时:
语句:
Ti:=PFileReco(vv); 根本没执行(当然还有ss:=@aa;没执行,但这条对程序没用!多余的bug)
为什么程序会不执行Ti:=PFileReco(vv);呢?
在qq吗,希望能聊聊,你的程序执行出来的结果是乱码?
Ti:=PFileReco(vv); 根本没执行
不晓得怎么搞的!请指教!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
PFileReco = ^TFileReco; //<------新加的
TFileReco = Record
SFileName, SFileFullName : String;
FileSize : Integer;
FileAttrib : Integer;
FileDateTime : TFileTime;
IsDir : Boolean;
end;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function huabo(var ss:pointer):boolean; //<---以前定义为 ss:pointer现在改为变参 前面加 var
end;var
Form1: TForm1;implementation{$R *.dfm}
var aa:TFileReco; //<-----从函数中移出,保证不会越出生存期
function TForm1.huabo(var ss: pointer): boolean;
begin
aa.SFileName:='adfajsfjasdf';
ss:=@aa;
result:=true;
end;procedure TForm1.Button1Click(Sender: TObject);
var Ti:PFileReco;
vv:pointer;//variant
pp:TFileReco;begin
huabo(vv); Ti :=PFileReco(vv); //<------转化指针 ShowMessage(Ti.SFileName); //<-----读出内容 ,不会出现乱码// pp:=vv);
// Ti:=^pp;// showmessage(pchar(^vv.SFileName));end;
end.
大哥,太感谢你了!我的qq是:55268867 有空交流交流!
以前定义为 ss:pointer现在改为变参 前面加 var 为什么要加var呢?
var aa:TFileReco; //<-----从函数中移出,保证不会越出生存期?生存周期很早就听过了,但对她的机制一直搞不懂?不晓得哪有这方面的资料,或者详细说明,请指教!
ShowMessage(Ti.SFileName); //<-----读出内容 ,不会出现乱码 中的Ti.SFileName改写为Ti^.SFileName也能读出数据!请问这两种写法有什么区别?
@Ti.SFileName又代表什么?@Ti^.SFileName代表什么?
请多指教,此问题分数加为500分?
谢谢关注!有资料更好!详细或者不详细测试没测试都行!
为什么用pfilereco就不会出错了呢,pfilereco还不是^Tfilereco???