⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmllst.pas

📁 一套及时通讯的原码
💻 PAS
字号:
unit MMLLst;

{$I COMPILER.INC}

interface

uses
    Windows,
    SysUtils,
    Classes;

// Creates a list
function  List_Create(dwNodeSize: DWORD): THandle;
// Destroys a list
procedure List_Destroy(hList: THandle);

// Allocates a new node for a list
function  List_Allocate(hList: THandle): THandle;
// Destroys a list
procedure List_Deallocate(hNode: THandle);

// Attaches a node to the list.
procedure List_Attach(hList, hNode: THandle);
// Attaches a node to the end of the list.
procedure List_Attach_Tail(hList, hNode: THandle);
// Inserts a node into a list.
procedure List_Insert(hList, hNode, hNodeAfter: Thandle);

// Removes a node from the list.
function  List_Remove(hList, hNode: THandle): Boolean;

// Removes the first node in list.
function  List_Remove_First(hList: THandle): THandle;

// Returns the address of the first node.
function  List_Get_First(hList: THandle): THandle;

// Returns the address of next node in the list.
function  List_Get_Next(hList, hNode: THandle): THandle;

implementation

type
    TMyList = class(TList)
    public
       Tag: integer;
    end;

{-- Creates a list ------------------------------------------------------------}
function List_Create(dwNodeSize: DWORD): THandle;
var
   P: TMyList;
begin
   P := TMyList.Create;
   P.Tag := dwNodeSize;
   Result := THandle(P);
end;

{-- Destroys a list -----------------------------------------------------------}
procedure List_Destroy(hList: THandle);
begin
   if (hList <> 0) then
   begin
      TMyList(hList).Free;
   end;
end;

{-- Allocates a new node for a list -------------------------------------------}
function List_Allocate(hList: THandle): THandle;
var
   P: Pointer;
begin
   P := nil;
   if (hList <> 0) then
       GetMem(P,TMyList(hList).Tag);
   Result := THandle(P);
end;

{-- Destroys a list -----------------------------------------------------------}
procedure List_Deallocate(hNode: THandle);
begin
   if (hNode <> 0) then
   begin
      FreeMem(Pointer(hNode));
   end;
end;

{-- Attaches a node to the list -----------------------------------------------}
procedure List_Attach(hList, hNode: THandle);
begin
   if (hList <> 0) and (hNode <> 0) then
   begin
      TMyList(hList).Insert(0,Pointer(hNode));
   end;
end;

{-- Attaches a node to the end of the list ------------------------------------}
procedure List_Attach_Tail(hList, hNode: THandle);
begin
   if (hList <> 0) and (hNode <> 0) then
   begin
      TMyList(hList).Add(Pointer(hNode));
   end;
end;

{-- Inserts a node into a list ------------------------------------------------}
procedure List_Insert(hList, hNode, hNodeAfter: Thandle);
var
   idx: integer;
begin
   if (hList <> 0) and (hNode <> 0) then
   begin
      idx := TMyList(hList).IndexOf(Pointer(hNodeAfter));
      TMyList(hList).Insert(idx,Pointer(hNode));
   end;
end;

{-- Removes a node from the list ----------------------------------------------}
function List_Remove(hList, hNode: THandle): Boolean;
begin
   Result := False;
   if (hList <> 0) and (hNode <> 0) then
   begin
      if (TMyList(hList).IndexOf(Pointer(hNode)) >= 0) then
          Result := TMyList(hList).Remove(Pointer(hNode)) >= 0;
   end;
end;

{-- Removes the first node in list --------------------------------------------}
function List_Remove_First(hList: THandle): THandle;
begin
   Result := 0;
   if (hList <> 0) then
   begin
      if (TMyList(hList).Count > 0) then
      begin
         Result := THandle(TMyList(hList).First);
         TMyList(hList).Delete(0);
      end;
   end;
end;

{-- Returns the address of the first node -------------------------------------}
function List_Get_First(hList: THandle): THandle;
begin
   Result := 0;
   if (hList <> 0) then
   begin
      if (TMyList(hList).Count > 0) then
          Result := THandle(TMyList(hList).First);
   end;
end;

{-- Returns the address of next node in the list ------------------------------}
function List_Get_Next(hList, hNode: THandle): THandle;
var
   idx: integer;
begin
   Result := 0;
   if (hList <> 0) then
   begin
      idx := TMyList(hList).IndexOf(Pointer(hNode));
      if (idx >= 0) and (idx+1 < TMyList(hList).Count) then
         Result := THandle(TMyList(hList)[idx+1]);
   end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -