首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

求帮忙解释上代码

2013-01-08 
求帮忙解释下代码TypeTForm1 classTSocketThreadClass(TThread)privateFileMapPointer:PByteprotecte

求帮忙解释下代码
Type
   TForm1 = class;
   TSocketThread=Class(TThread)
  private

    FileMapPointer:PByte;
   protected

   public
    constructor Create(F:TForm1;Index:integer;offset:DWord;Count:Dword;FileMap:PByte); reintroduce;

  end;



constructor TSocketThread.Create(F:TForm1;Index:integer;offset:Dword;Count:Dword;FileMap:PByte);
var Iswork:Boolean;
begin
  //省略....
  INC(FileMapPointer,Offset);
  //省略....
  IF Index=0 then
  Iswork:=False
    else
    Iswork:=true;
  inherited Creater(Iswork);
end;

求指教下 INC(FileMapPointer,Offset) 这句怎么理解啊 FileMapPointer是 PByte类型Offset是Dword类型 这样写不会报错可是我写成FileMapPointer:=FileMapPointer+Offset;就报错了 ,Inc(x,y)不就是x:=x+y吗?


还有一个继承Thread的类的TSockThread的create方法中的inherited Create(iswork)是表达了什么? 我明白继承,可是这里理解不能!

[解决办法]
1.
Inc(X,N); X可以是指针类型,指针+1,或指针+N是啥呢? 就是移动指针,让它指向另外的数

2.
inherited是继承的意思,这里是调用父类的Create函数;

TThread有一个构造函数Create,函数中还有一个参数,带了默认值
当然可以直接用inherited;但用inherited Creater(Iswork);
表示,调用父类的Create函数,参数使用Iswork,而不是使用它的默认值

[解决办法]
1:这是inc()对于指针的一个特殊用法,但指针不能通过运算符自加。

[解决办法]
更正一下,线程类TThread的Create函数不能直接使用inherited;
必须是inherited create(true/false);这样的形式

[解决办法]
还有,Create()方法一定要标识override,否则它会提示“覆盖同名方法”并无法inherited;
[解决办法]
1、指针加步长,c是可以任意加
delphi只能用inc

2、相当于把父类的创建函数执行一次

热点排行