两个类声明如下:TParent = class
end;TChild = class(TParent)
private
FMyData: string;
public
procedure ShowMyMsg;
property MyData: string read FMyData write FMyData;
end;我使用时这样写的:var
P: TParent;
S: string;
begin
(P as TChild).MyData; //这句编译不过
S := (P as TChild).MyData; //这样就能编译过
(P as TChild).ShowMyMsg; //这样也可以
end;编译不过去的提示是Statement expected, but expression of type 'String' found,意识好象是需要一个方法而不是类型。
请问为什么会这样呢?如果我需要把那一句编译过去,该怎么修改呢?谢谢!分不多,只有这么多了,全部家当拿出来了。
end;TChild = class(TParent)
private
FMyData: string;
public
procedure ShowMyMsg;
property MyData: string read FMyData write FMyData;
end;我使用时这样写的:var
P: TParent;
S: string;
begin
(P as TChild).MyData; //这句编译不过
S := (P as TChild).MyData; //这样就能编译过
(P as TChild).ShowMyMsg; //这样也可以
end;编译不过去的提示是Statement expected, but expression of type 'String' found,意识好象是需要一个方法而不是类型。
请问为什么会这样呢?如果我需要把那一句编译过去,该怎么修改呢?谢谢!分不多,只有这么多了,全部家当拿出来了。
var
s: string;
begin
s;
end;
(P as TChild).MyData; //这句编译不过
这句根本没有意义
对一个变量既不读又不写,什么用都没有,写出来有什么用呢?
一个变量能单独当一句么?
这仅仅相当与一个变量 你对变量没有做任何的操作
没赋值 也没运算
它怎么就能编译过呢 ?