Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Problemas con estructuras (https://www.clubdelphi.com/foros/showthread.php?t=53545)

godel 23-02-2008 11:01:53

Problemas con estructuras
 
Hola a todos:

Como ya puse en el otro hilo , soy muy nuevo en Delpie y ademas nunca en mi vida programe en Pascal , afortunadamente para mi .

Estoy intentando invocar una pila y no se que hago mal , ya tuve problemas con las tablas hash y al final era que debía de instalar un paquete adicional por que Delphi no tiene de serie . Mi pregunta es como se invoca una pila , yo he hecho esto
Código Delphi [-]
unit Compilador;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, HashTrie, Stack ;

type

  TForm1 = class(TForm)

    procedure FormCreate(Sender: TObject);
  private
    htable :TStringHashTrie;
    htable2 : TStringHashTrie;
    Stack : TStack;
   //procedure ShowTable;
  public

  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
var
  miLista:TStringList;
  listaAux :TStringList;
  Stack: TStack;

pero nada me sale error , he buscado y me salen muchas web donde me dicen que me baje un paquete de estructuras , ¿he de bajarme un paquete para una pila ? y para hacer listas de listas he de hacer lo mismo , por qye no se si TTable se puede usar.


Gracias anticipadas

Lepe 23-02-2008 11:14:15

En la ayuda dice esto:
Cita:

TStack maintains a last-in first-out array of pointers.

Unit
Contnrs

por tanto, debe que dar así:
Código Delphi [-]
unit Compilador;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, HashTrie,
  Contnrs // la unidad que viene en la ayuda "Unit"
  ;

type

  TMiObjeto = class(TObject);
    public
       nombre:string;
   end;

  TForm1 = class(TForm)

    procedure FormCreate(Sender: TObject);
  private
    htable :TStringHashTrie;
    htable2 : TStringHashTrie;
    Stack : TStack;
   //procedure ShowTable;
  public

  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
var
  miLista:TStringList;
  listaAux :TStringList;
  Stack: TStack;
  c :TMiObjeto;
begin
   Stack := TStack.Create; // adquirimos memoria y creamos el objeto


   Stack.free; // finalmente para destruirlo

Te aconsejo que mires en la ayuda, yaque existe TObjectQueue y TobjectStack que son más fáciles de usar, así como otros tipos de pilas LIFO y FIFO.

Saludos

godel 23-02-2008 12:36:25

Muchas Gracias por el consejo lo probare y haber como queda .

Delphius 23-02-2008 13:08:34

Amigo Lepe, creo que un error al hacer copy/paste;).
Modificando un poquito el codigo creo que va a funcionar:
Código Delphi [-]
unit Compilador;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, HashTrie,
  Contnrs // la unidad que viene en la ayuda "Unit"
  ;

type

  TMiObjeto = class(TObject);
    public
       nombre:string;
   end;

  TForm1 = class(TForm)

    procedure FormCreate(Sender: TObject);
  private
    htable :TStringHashTrie;
    htable2 : TStringHashTrie;
    Stack : TStack;
   //procedure ShowTable;
  public

  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
{ ya la tenemos en el private del form!
var
  miLista:TStringList;
  listaAux :TStringList;
  Stack: TStack;
  c :TMiObjeto;
  estas variables están de más!
}
begin
   Stack := TStack.Create; // adquirimos memoria y creamos el objeto

...
end;

Saludos,


La franja horaria es GMT +2. Ahora son las 17:17:46.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi