求助:用C++Builder写的一个关于STL基本操作,如何用Delphi来实现相应的功能。
刚刚接触Delphi,原来用BCB时,由于有STL,所以用链表(list)、向量(vector)等来实现某些功能很方便,现在转到Delphi下,不知用什么方法来实现类似的功能呢?看以下一个简单的示例:
------Unit.h:
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <list.h>
//---------------------------------------------------------------------------
struct PollTable
{
AnsiString IPAddr;
AnsiString OID;
int ID;
} ;
typedef list<PollTable*> PollTableList ;
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TButton *Button1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
PollTableList mPollTableList;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
------Unit.cpp:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
PollTable *Poll = new PollTable;
Poll->IPAddr = "192.168.0.1";
Poll->OID = "1.3.6.1.4.2";
Poll->ID = 1;
mPollTableList.push_back(Poll);
PollTable *Poll2 = new PollTable;
Poll2->IPAddr = "192.168.0.1";
Poll2->OID = "1.3.6.1.4.2";
Poll2->ID = 2;
mPollTableList.push_back(Poll2);
PollTable *Poll3 = new PollTable;
Poll3->IPAddr = "192.168.0.1";
Poll3->OID = "1.3.6.1.4.2";
Poll3->ID = 3;
mPollTableList.push_back(Poll3);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
list<PollTable*>:: iterator first = mPollTableList.begin();
list<PollTable*>:: iterator last = mPollTableList.end();
while(first != last)
{
if ( (*first)->ID == 3 )
{
mPollTableList.erase(first);
delete *first;
break;
}
first++;
}
Edit1->Text = IntToStr(mPollTableList.size());
}