unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Contnrs;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
ccc: Char;
myQueue: TQueue;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ccc := 'A';
myQueue := TQueue.Create();
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
myQueue.Free();
end;
procedure TForm1.Button1Click(Sender: TObject);
var
buf: PChar;
begin
GetMem(buf, 2);
buf[0] := ccc;
buf[1] := #0;
myQueue.Push(buf);
inc(ccc);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
buf: PChar;
begin
if myQueue.Count = 0 then
begin
ShowMessage('此队列为空队列!!!');
Exit;
end;
buf := myQueue.Pop();
if buf = nil then
begin
ShowMessage('取出的是空指针。');
end
else
begin
ShowMessage('取出: ' + buf);
FreeMem(buf);
end
end;
end.