Ver Mensaje Individual
  #5  
Antiguo 08-02-2007
miguel_e miguel_e is offline
Miembro
 
Registrado: ene 2006
Posts: 86
Reputación: 19
miguel_e Va por buen camino
Hola de nuevo, TActionList no hereda de nadie, esta es la lista de acciones, el tiene un campo que es un TStringList el cual almacena los objetos que heredan de TAction.

aqui te pongo la interface:

Código:
TActionList = class
  private
    FPath : string;
    FList : TStringList;
  public
    constructor Create(aPath : string); reintroduce;
    destructor Destroy; override;

    procedure Add(action : TAction);
    function Delete(IdTask : string): Boolean;
    function Count: Integer;
    function IsEmpty: Boolean;
    function getAction(aIndex : integer): TAction; overload;
    function getAction(aIdTask : string): TAction; overload;

    procedure DefineProperty(aFiler : TFiler);
    procedure LoadActions(aReader : TReader);
    procedure SaveActions(aWriter : TWriter);
  end;
La clase TActionList o la lista de acciones es la que deseo hacer persistentes, el problema radica en que no se como hacerlo, y que he visto algunos ejemplos que no me han ayudado del todo, por ejemplo:

Código:
procedure TActionList.DefineProperty(aFiler: TFiler);
begin
  inherited;
  aFiler.DefineProperty('Action', LoadActions, SaveActions, true);
end;
Este metodo se usa para guardar en un fichero, se le ponen los nombres de los dos metodos(tanto salvar, como cargar), pero no se de quien entonces debe heredar TActionList, de TComponent????? Luego los metodos que salvan y cargan los objetos.

Código:
procedure TActionList.LoadActions(aReader: TReader);
var
  StrId : string;
  aAction : TAction;
begin
  aReader.ReadListBegin;
  While not aReader.EndOfList Do
  begin                                   
    StrId := aReader.ReadStr;
    aAction := (aReader.ReadComponent(nil) as TAction);
    FList.AddObject(StrId, aAction);
  end;
  aReader.ReadListEnd;
end;

procedure TActionList.SaveActions(aWriter: TWriter);
var
  i : integer;
begin
  aWriter.WriteListBegin;
  For i := 0 to FList.Count - 1 Do
  begin
    aWriter.WriteString(FList[i]);
    aWriter.WriteComponent(FList.Objects[i] as TAction);
  end;
  aWriter.WriteListEnd; 
end;
Pero esto no logro hacer que funcione, porque me faltan cosas que no se.

entonces la preguntas concretas serian:

- De quien deberia heredar TActionList???
- Donde se le dice que salve y que carge, o lo hace automatico??????
- Existe otra manera de resolver mi problema???
- Cuando cargo del fichero voy a agregando a la lista objetos tipo TActions, no habra problema al llamar a estos objetos, ya que no reconoceran el tipo especializado que eran anteriormente

salu2
miguel_e
Responder Con Cita