Forum > Spanish

iteradoras en pascal

<< < (2/3) > >>

zelda16bit:
Y si creo una lista de objetos y luego le añado a esa lista 20 objetos,para despues mostrar esos 20 objetos.Y al final ir eliminando uno a uno esos 20 objetos y luego los vuelvo a mostrar para ver el resultado,como seria.

KodeZwerg:

--- Quote from: zelda16bit on February 21, 2023, 03:27:21 pm ---Y si creo una lista de objetos y luego le añado a esa lista 20 objetos,para despues mostrar esos 20 objetos.Y al final ir eliminando uno a uno esos 20 objetos y luego los vuelvo a mostrar para ver el resultado,como seria.

--- End quote ---

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;{$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF} {$mode objfpc} uses  generics.Collections; type  TIntegerList = specialize TList<integer>;var  integers : array of integer = (10,11,12,13,14,15);  list: TIntegerList;  item: integer;  i: integer;begin  list := TIntegerList.Create;   // quickly add integer items to list  for item in integers    do List.Add(item);   // iterate over list and display each item  for item in list    do writeln(item);   writeln('deleted last 3');   for i := 0 to 2 do    List.Delete(Pred(List.Count));   for item in list    do writeln(item);   list.Free;  {$IFDEF MSWINDOWS}ReadLn; {$ENDIF}end.

zelda16bit:

--- Quote from: KodeZwerg on February 21, 2023, 03:35:10 pm ---
--- Quote from: zelda16bit on February 21, 2023, 03:27:21 pm ---Y si creo una lista de objetos y luego le añado a esa lista 20 objetos,para despues mostrar esos 20 objetos.Y al final ir eliminando uno a uno esos 20 objetos y luego los vuelvo a mostrar para ver el resultado,como seria.

--- End quote ---

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;{$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF} {$mode objfpc} uses  generics.Collections; type  TIntegerList = specialize TList<integer>;var  integers : array of integer = (10,11,12,13,14,15);  list: TIntegerList;  item: integer;  i: integer;begin  list := TIntegerList.Create;   // quickly add integer items to list  for item in integers    do List.Add(item);   // iterate over list and display each item  for item in list    do writeln(item);   writeln('deleted last 3');   for i := 0 to 2 do    List.Delete(Pred(List.Count));   for item in list    do writeln(item);   list.Free;  {$IFDEF MSWINDOWS}ReadLn; {$ENDIF}end.
--- End quote ---

Como seria con una clase.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  Tclase = class    numero: integer;    numero2: integer;    property propiedad: integer read numero2 write numero2;    procedure metodo();  end; procedure Tclase.metodo();begin  writeln('el numero es: ',numero+10);end; 

TRon:
@KodeZwerg: Thank you !

@zelda16bit:
your question translates for me to

--- Quote ---As it would be with a class.

--- End quote ---
In combination with your code the remark that you made does not make any sense to me so I have no idea what exactly you are asking for or are referring to.

Translated with an online translator to Spanish:

--- Quote ---En combinación con su código, el comentario que hizo no tiene ningún sentido para mí, así que no tengo idea de qué es exactamente lo que está pidiendo o a lo que se refiere.

--- End quote ---

KodeZwerg:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;{$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF} {$mode objfpc} uses  Generics.Collections; type   { TCustomList }  TIntegerList = specialize TList<integer>;  TCustomList = class(TObject)    strict private      FCount: Integer;      FIndex: Integer;      FCurrent: Integer;      FList: TIntegerList;    private      procedure SetCount(const AValue: Integer);      procedure SetIndex(const AValue: Integer);      function GetCurrent: Integer;      procedure SetCurrent(const AValue: Integer);    public      constructor Create;      destructor Destroy; override;      procedure Add(const AValue: Integer);      procedure Show;      procedure Remove(const AIndex: Integer);    published      property Count: Integer read FCount write SetCount default 0;      property Index: Integer read FIndex write SetIndex default -1;      property Current: Integer read GetCurrent write SetCurrent default -1;  end; { begin TCustomList }constructor TCustomList.Create;begin  inherited Create;  FList := TIntegerList.Create;  FCount := 0;  FIndex := -1;  FCurrent := -1;end; destructor TCustomList.Destroy;begin  FList.Free;  FList := nil;  inherited Destroy;end; procedure TCustomList.SetIndex(const AValue: Integer);begin  if ((AValue >= 0) and (AValue < FCount)) then    FIndex := AValue    else    FIndex := -1;end; function TCustomList.GetCurrent: Integer;begin  if ((FIndex >= 0) and (FIndex < FCount)) then    Result := FList.Items[FIndex]    else    Result := -1;end; procedure TCustomList.SetCurrent(const AValue: Integer);begin  if ((FIndex >= 0) and (FIndex < FCount)) then    FList.Items[FIndex] := AValue;end; procedure TCustomList.SetCount(const AValue: Integer);var  i: Integer;begin  if (FCount = 0) then    Exit;  if (AValue < FCount) then    for i := Pred(FCount) downto AValue do      FList.Delete(i);  FCount := FList.Count;  FIndex := Pred(FCount);end; procedure TCustomList.Add(const AValue: Integer);begin  FList.Add(AValue);  FCount := FList.Count;  FIndex := Pred(FCount);end; procedure TCustomList.Remove(const AIndex: Integer);begin  if (FCount = 0) then    Exit;  if ((AIndex >= 0) and (AIndex < FCount)) then    FList.Delete(AIndex);  FCount := FList.Count;  FIndex := Pred(FCount);end; procedure TCustomList.Show;var  i: Integer;begin  if (FCount = 0) then    Exit;  for i in FList    do WriteLn(i);end;{ end TCustomList } var  List: TCustomList;  i: integer;begin  List := TCustomList.Create;  try    WriteLn('Add 10 elements');    for i := 0 to 9 do      List.Add(i);    WriteLn('Show all elements');    List.Show;    WriteLn('Remove last 5 elements');    List.Count := List.Count - 5;    WriteLn('Show all elements');    List.Show;    WriteLn('Change value of element 3 to 99');    List.Index := 2;    List.Current := 99;    WriteLn('Show all elements');    List.Show;  finally    List.Free;  end;  {$IFDEF MSWINDOWS}ReadLn; {$ENDIF}end.¿Supongo que querías esta lista en una clase?

--- Quote ---I assume you wanted this list in a class?
--- End quote ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version