type
JgData=record
jgm:string;
jgmc:string;
end;
type
SbData=record
sbbh:integer;
sbxh:string;
sblx:string;
sbxl:integer;
end;
type Pjg=^JgData;
type PSb=^SbData;jg:pjg;
sb:psb;aa:pointer;aa可能用aa:=jg;赋值,也可能用aa:=sb赋值在程序后面处理的时候,要先判断aa是jg还是sb,该怎样判断?语句如何写?
如果事先已知道类型,可用JgData(aa^)或SbData(aa^)来取得结构的内容,可是现在不知道如何确定aa的类型。
JgData=record
jgm:string;
jgmc:string;
end;
type
SbData=record
sbbh:integer;
sbxh:string;
sblx:string;
sbxl:integer;
end;
type Pjg=^JgData;
type PSb=^SbData;jg:pjg;
sb:psb;aa:pointer;aa可能用aa:=jg;赋值,也可能用aa:=sb赋值在程序后面处理的时候,要先判断aa是jg还是sb,该怎样判断?语句如何写?
如果事先已知道类型,可用JgData(aa^)或SbData(aa^)来取得结构的内容,可是现在不知道如何确定aa的类型。
type
JgData=record
sign:byte;/////////
jgm:string;
jgmc:string;
end;
type
SbData=record
sign:byte/////////
sbbh:integer;
sbxh:string;
sblx:string;
sbxl:integer;
end;
每次判断的时候先牵制转化成一种类型,例如pjg然后判断sign是多少,这里的sign相当于一个编号...
type
Pjg=^JgData;
PSb=^SbData; JgData=record
iType:byte;
jgm:string;
jgmc:string;
end; SbData=record
iType:byte;
sbbh:integer;
sbxh:string;
sblx:string;
sbxl:integer;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
new(jg);
new(sb);
jg^.iType:=0;
sb^.iType:=1;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
if byte(aa^)=0 then
Label1.Caption:='pjg'
else
Label1.Caption:='psb';
end;
sign:byte;
jgm:string;
jgmc:string;
end;
SbData=record
sign:byte;
sbbh:integer;
sbxh:string;
sblx:string;
sbxl:integer;
end;
type Pjg=^JgData;
type PSb=^SbData;
var
Form1: TForm1;
jg:pjg;
sb:psb;
temp:JgData; aa:pointer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
temp.sign:=1;
temp.jgm:='Hello';
temp.jgmc:='World'; aa:=@temp;
if pjg(aa).sign=1 then showmessage('aa的类型是指向JgData的指针!');end;
JgData(aa^).jgm是否合法的串
或者
SbData(aa^).sbbh是否合法的整数
来确定aa的类型。
if aa^.jgm='' then
;
except
;
end如果发生异常说明是sb
->
type
TRecordEnum =
(reJgData, reSbData); MyPointer = record
pData: Pointer;
DataType: TRecordEnum;
end;ok?