vladman Цитата: Как вам будет удобней. Но также можно воспользоваться тэгом more (http://i.ru-board.com/codes.html) или ПМ.
Попробую воспользоваться тэгом more.
Это файл Main.h [more]
//---------------------------------------------------------------------------
#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include "edbcomps.hpp"
#include "cxGrid.hpp"
#include "cxGridCustomTableView.hpp"
#include "cxGridCustomView.hpp"
#include "cxGridDBTableView.hpp"
#include "cxGridLevel.hpp"
#include "cxGridTableView.hpp"
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private: // User declarations
TPanel* MyPanel;
TButton* MyBtnCreateBase;
TButton* MyBtnCreateGrid;
TButton* MyBtnRemoveGrid;
TEDBEngine* MyEngine;
TEDBSession* MySession;
TEDBDatabase* MyBase;
TEDBTable* MyTable;
TDataSource* MyDataSource;
TcxGrid* grid;
private:
void __fastcall MyEngineBeforeStart(TObject *Sender);
void __fastcall MyBtnCreateBaseClick(TObject *Sender);
void __fastcall MyBtnCreateGridClick(TObject *Sender);
void __fastcall MyBtnRemoveGridClick(TObject *Sender);
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
[/more]
А это файл Main.cpp [more]
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
const int RecCount=5000;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner)
{
MyEngine=NULL;
MySession=NULL;
MyBase=NULL;
MyTable=NULL;
MyDataSource=NULL;
grid=NULL;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
WindowState=wsMaximized;
// Create controls
MyPanel=new TPanel(this);
MyPanel->Parent=this;
MyPanel->Height=45;
MyPanel->Align=alBottom;
MyBtnCreateBase=new TButton(MyPanel);
MyBtnCreateBase->Parent=MyPanel;
MyBtnCreateBase->Width=250;
MyBtnCreateBase->Left=10;
MyBtnCreateBase->Top=10;
MyBtnCreateBase->Caption="Create database and TestTable";
MyBtnCreateBase->OnClick=MyBtnCreateBaseClick;
MyBtnCreateGrid=new TButton(MyPanel);
MyBtnCreateGrid->Parent=MyPanel;
MyBtnCreateGrid->Width=250;
MyBtnCreateGrid->Left=270;
MyBtnCreateGrid->Top=10;
MyBtnCreateGrid->Caption="Create TcxGrid and show TestTable";
MyBtnCreateGrid->OnClick=MyBtnCreateGridClick;
MyBtnRemoveGrid=new TButton(MyPanel);
MyBtnRemoveGrid->Parent=MyPanel;
MyBtnRemoveGrid->Width=250;
MyBtnRemoveGrid->Left=530;
MyBtnRemoveGrid->Top=10;
MyBtnRemoveGrid->Caption="Remove TcxGrid";
MyBtnRemoveGrid->OnClick=MyBtnRemoveGridClick;
// Create empty data directory
String DataPath=Sysutils::ExtractFilePath(Application->ExeName)+"Data\\";
if(DirectoryExists(DataPath))
{
// Remove not empty directory
SHFILEOPSTRUCT sh;
sh.hwnd=Handle;
sh.wFunc = FO_DELETE;
sh.pFrom = DataPath.t_str();
sh.pTo = NULL;
sh.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
sh.hNameMappings = 0;
sh.lpszProgressTitle = NULL;
SHFileOperation(&sh);
}
CreateDirectory(DataPath.t_str(),NULL);
// Create ElevateDB engine
MyEngine=new TEDBEngine(this);
MyEngine->ConfigPath=DataPath;
MyEngine->BeforeStart=MyEngineBeforeStart;
MyEngine->Active=true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
if(grid) delete grid;
if(MyDataSource) delete MyDataSource;
if(MyTable)
{
MyTable->Active=false;
delete MyTable;
}
if(MyBase)
{
MyBase->Connected=false;
delete MyBase;
}
if(MySession) delete MySession;
if(MyEngine)
{
MyEngine->Active=false;
delete MyEngine;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MyEngineBeforeStart(TObject *Sender)
{
MySession=MyEngine->FindSession("Default");
if(MySession)
{
MySession->LoginUser="Administrator";
MySession->LoginPassword="EDBDefault";
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MyBtnCreateBaseClick(TObject *Sender)
{
// Create base in memory
String BaseName="Test";
String BaseDesc="Test database";
String sql;
sql.printf(L"CREATE DATABASE \"%s\" IN MEMORY DESCRIPTION '%s'",BaseName,BaseDesc);
TEDBQuery* query=new TEDBQuery(this);
query->DatabaseName="Configuration";
query->SQL->Text=sql;
query->ExecSQL();
delete query;
MyBase=new TEDBDatabase(this);
MyBase->Database=BaseName;
MyBase->DatabaseName=BaseName;
// Create TestTable
String s,FldName,TableName="TestTable";
int FldCount=30,FldWidth=32;
int FldCount1=FldCount-1;
sql.printf(L"CREATE TABLE %s (",TableName);
for(int i=0;i<FldCount;i++)
{
FldName.printf(L"Field%02d",i);
s.printf(L"%s VARCHAR(%d)",FldName,FldWidth);
if(i<FldCount1) s+=",";
sql+=s;
}
sql+=")";
MyBase->Execute(sql);
// Fill TestTable
sql.printf(L"INSERT INTO %s VALUES (",TableName);
for(int i=0;i<FldCount;i++)
{
s.printf(L"'value for field %02d'",i);
if(i<FldCount1) s+=",";
sql+=s;
}
sql+=")";
for(int i=0;i<RecCount;i++)
{
s.printf(L"Add record: %d of %d",i+1,RecCount);
Caption=s;
MyBase->Execute(sql);
}
ShowMessage(L"TestTable is filled!");
s.printf(L"TestTable: RecCount=%d",RecCount);
Caption=s;
// Open TestTable
MyTable=new TEDBTable(this);
MyTable->DatabaseName=BaseName;
MyTable->TableName=TableName;
MyTable->Active=true;
// Create DataSource
MyDataSource=new TDataSource(this);
MyDataSource->DataSet=MyTable;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MyBtnCreateGridClick(TObject *Sender)
{
// Create and tune grid
grid=new TcxGrid(this);
grid->Parent=this;
grid->Align=alClient;
TcxGridLevel* level=grid->Levels->Add();
TcxGridDBTableView* view=(TcxGridDBTableView*)grid->CreateView(__classid(TcxGridDBTableView));
level->GridView=view;
view->FilterBox->CustomizeDialog=true;
view->FilterBox->Position=fpBottom;
view->FilterBox->Visible=fvAlways;
view->OptionsBehavior->GoToNextCellOnEnter=true;
view->OptionsBehavior->IncSearch=true;
view->OptionsBehavior->NavigatorHints=true;
view->OptionsCustomize->ColumnsQuickCustomization=true;
view->OptionsView->CellEndEllipsis=true;
view->OptionsView->Footer=true;
view->OptionsView->HeaderEndEllipsis=true;
view->OptionsView->Indicator=true;
view->OptionsView->Navigator=true;
view->OptionsView->ShowColumnFilterButtons=sfbAlways;
view->DataController->DataSource=MyDataSource;
view->DataController->CreateAllItems();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MyBtnRemoveGridClick(TObject *Sender)
{
if(grid)
{
grid->BeginUpdate(); // don't help
MyTable->DisableControls(); // don't help
TcxGridLevel* level=grid->Levels->Items[0];
level->Active=false; // don't help
TcxGridDBTableView* view=(TcxGridDBTableView*)level->GridView;
view->ClearItems(); // don't help
view->DataController->DataSource->DataSet=NULL; // don't help
view->DataController->DataSource=NULL; // don't help
MyTable->Close(); // don't help
grid->EndUpdate(); // don't help
delete grid;
grid=NULL;
Repaint();
}
}
//---------------------------------------------------------------------------
[/more]
Неужели для таблицы с большим числом записей удаление TcxGrid требует много времени?
Пробовал для базы, размещенной в памяти и на диске.
Что я делаю не так?