TMydefault = class(TObject)
  private
  protected   function Get(Index: Integer):TMyType; virtual; abstract;
   procedure Put(Index: Integer;const Value:TMyType);virtual;
  public
    FList:array [0..254] of TMyType;    constructor Create;
    destructor Destroy; override;    property List[Index: Integer]: TMyType read Get write Put;default;
  published  end;procedure TMydefault.Put(Index: Integer;const Value:TCheckAndText);
begin
  FList[Index]:= Value;
end;TStrings;
function Get(Index: Integer): string; virtual; abstract;
procedure Put(Index: Integer; const S: string); virtual;property Strings[Index: Integer]: string read Get write Put; default;procedure TStrings.Put(Index: Integer; const S: string);
var
  TempObject: TObject;
begin
  TempObject := GetObject(Index);
  Delete(Index);
  InsertObject(Index, S, TempObject);
end;
为什么 我的就不行?

解决方案 »

  1.   

    TStrings是delphi内部的类,你能自己创建吗
      

  2.   

    你的怎么了?有什么问题么?
    如果就像现在这么写的,Get是个没有被继承的抽象方法,如果访问抽象方法的法,自然会报abstract错误
      

  3.   

     目前沒有發現哪裏有錯誤。呵呵 get  是抽象的,要在繼承中實現,你也沒有寫,所以也沒有錯。 你說的哪裏不行呢?兄弟
      

  4.   

    Mydefault[0].TMyType成员:=False;
    [Error] Left side cannot be assigned to
      

  5.   


      TMydefault = class(TObject)
      private
      protected   function Get(Index: Integer):TMyType; virtual; abstract;
       procedure Put(Index: Integer;const Value:TMyType);virtual;
      public
        FList:array [0..254] of TMyType;    constructor Create;
        destructor Destroy; override;    property List[Index: Integer]: TMyType read Get write Put;default;
      published  end;procedure TMydefault.Put(Index: Integer;const Value:TMyType);
    begin
      FList[Index]:= Value;
    end;
      

  6.   

    ……
    这个用法够有创意的
    按照c语言常用的概念,delphi的属性是个左值(lvalue),通俗点儿讲,不能被取地址的值。一个不能被取地址的值,你访问它的成员变量当然是不可能了
      

  7.   

    一堆手误……properties“不是左值”,右值是不能取地址操作的;而是不能通过直接访问右值改变成员变量的值
    也就是说,你只能先定义一个TMyType的变量,然后整体把TMyType给property,而不可能只把TMyType的成员变量的值给property
      

  8.   

    问题是我差不多 照般了TStrings 怎么还是不行?
    TStrings  怎么又可以?
      

  9.   


    你在哪裏看到可以了!你自己定的義TMYCLIASS的數組在哪裏?
      

  10.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, 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{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      Strings:TStrings;
    begin
      Strings:= TStrings.Create;  Strings.Add('我日');
      Strings[0]:='我再日';
      ShowMessage(Strings[0]);
      Strings.Free;end;end.运行抱错 abstract
    编译能过
    怎么我的编都编不过
    是不是还要派生一个类才行?
      

  11.   

    请教下 starluck
    我要实现和 TStringList一样的效果该怎么写?
    就是 实例名[Index] 直接访问 这个实例的list的第Index个对象
      

  12.   

     你可以這樣,但不能你那樣去訪問成員變量。unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TMyType = class
        A : integer;
        b : integer;
      end;
    type
      TMydefault = class(TObject)
      private
      protected   function Get(Index: Integer):TMyType; virtual;
       procedure Put(Index: Integer;const Value:TMyType);virtual;
      public
        FList:array [0..254] of TMyType;    constructor Create;
        destructor Destroy; override;    property List[Index: Integer]: TMyType read Get write Put;default;
      published  end;type
      TForm2 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;
        vDef :  TMydefault;
    implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
    var
      v : TMyType;
    begin
      v := TMyType.Create;
      v.A := 10;
      v.b := 20;
      vDef[0] := V;
    end;procedure TForm2.Button2Click(Sender: TObject);
    begin
      showMessage(Inttostr(vdef[0].A));
    end;procedure TForm2.FormCreate(Sender: TObject);
    begin
      vDef := TMydefault.Create;
    end;{ TMydefault }constructor TMydefault.Create;
    beginend;destructor TMydefault.Destroy;
    begin  inherited;
    end;function TMydefault.Get(Index: Integer): TMyType;
    begin
      Result := FList[index];
    end;procedure TMydefault.Put(Index: Integer; const Value: TMyType);
    begin
      FList[Index] := Value;
    end;end.
      

  13.   


    type
      TMyType = class
        A : integer;
        b : integer;
      end;
    TMyType 不能是 record 吗 ?type
      TMyType = record
        A : integer;
        b : integer;
      end;
      

  14.   


    type
      TMyType = class
        A : integer;
        b : integer;
      end;
    TMyType 不能是 record 吗 ?type
      TMyType = record
        A : integer;
        b : integer;
      end;
      

  15.   

    测试你的代码才发现
    还是我那个样
    vDef[0] := V;
    这样可以 vDef[0].a 就不行 是不是肯定不行的
    实在不行我就用函数算了 
      

  16.   

    我前面不是跟你说了么?没法直接改不能取地址的变量的成员,而delphi的属性是不能取地址的
      

  17.   


    那就用两个函数吧
    一个读一个写
    get(index).a