Есть класс, в котором находятся некие данные в виде динамического массива:
| Код | TSimbaComponentList = class private SimbaList: array of TSimbaComponent; // Simba components storage public constructor Create; destructor Destroy; override; procedure AddItem(Item: TSimbaComponent;index: integer); procedure RemoveItem(Index: Integer); function GetComponent(Idx: integer): TSimbaComponent; function Count: integer; end;
implementation
{ TSimbaComponentList }
constructor TSimbaComponentList.Create; begin setlength(SimbaList,1); inherited Create; end;
destructor TSimbaComponentList.Destroy; begin SimbaList := nil; //free storage inherited Destroy; end;
procedure TSimbaComponentList.AddItem(Item: TSimbaComponent;index: integer); var len: integer; begin Len:= Length(SimbaList); if Index >= Len then Index := Len+1; setLength( SimbaList, Len+1); move( SimbaList[Index],SimbaList[ Index+1 ], (Len-Index) * sizeof( SimbaList[Index] )); SimbaList[Index] := Item; end;
procedure TSimbaComponentList.RemoveItem(Index: Integer); var last: integer; begin last := high(SimbaList); if Index < Last then move( SimbaList[Index+1], SimbaList[Index], (Last-Index) * sizeof( SimbaList[Index] ) ); setLength(SimbaList, Last ); end;
function TSimbaComponentList.GetComponent(Idx: integer): TSimbaComponent; begin result:= SimbaList[Idx]; end;
function TSimbaComponentList.Count: integer; begin Result := Length(SimbaList); end;
|
Создаю экземпляр этого класса, перед передачей в функцию - смотрю, он заполнен. Затем передаю в процедуру:
| Код | procedure TCodeGen.CreateScript(list: TSimbaComponentList); var i: integer; begin for i:=0 to list.Count -1 do begin CmpList.AddItem(list.GetComponent(i),i); end; GenerateFormCode(list); SynEdit1.Lines.AddStrings(ScriptCode); end;
|
- проверяю экземпляр класса, который должен был принять переданное - а он стабильно имеет 1 элемент. Как тут быть?
|