I followed this Delphi sample for accessing columns of a TIWDBGrid using C++Builder, but it does not work.
Below is my code:
__fastcall TForm1::TForm1(TComponent* Owner) : TFrame(Owner)
{//
TRESTClient *REST1Client = new TRESTClient(this);
TRESTRequest *REST1Request = new TRESTRequest(this);
TRESTResponse *REST1Response = new TRESTResponse(this);
TClientDataSet *ClientDataSet1 = new TClientDataSet(this);
TRESTResponseDataSetAdapter *REST1ResponseDataSetAdapter = new TRESTResponseDataSetAdapter(this);
TDataSource *DataSource1 = new TDataSource(this);
DataSource1->DataSet = ClientDataSet1;
IWDBGrid1->DataSource = DataSource1;
ClientDataSet1->AfterOpen = &ClientDataSet1AfterOpen;
REST1Client->BaseURL = "my.URL.php";
REST1Request->AddParameter("IdField", "IdValue");
REST1Request->Client = REST1Client;
REST1Request->Response = REST1Response;
REST1Response->ContentType = "application/json";
REST1ResponseDataSetAdapter->Dataset = ClientDataSet1;
REST1ResponseDataSetAdapter->Response = REST1Response;
REST1ResponseDataSetAdapter->Active = true;
REST1Request->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientDataSet1AfterOpen(TDataSet *DataSet)
{//
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[0])->Width = (IWDBGrid1->Width/20) * 02; // => Argument out of range
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[1])->Width = (IWDBGrid1->Width/20) * 02;
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[2])->Width = (IWDBGrid1->Width/20) * 13;
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[3])->Width = (IWDBGrid1->Width/20) * 03;
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[0])->Title->Text = "AFirstTitle";
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[1])->Title->Text = "ASecondTitle";
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[2])->Title->Text = "AThirdTitle";
static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[3])->Title->Text = "AFourthTitle";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IWDBGrid1Render(TObject *Sender)
{//
// static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[0])->Width = (IWDBGrid1->Width/20) * 02; // => Argument out of range
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IWFrameRegionRender(TObject *Sender)
{//
// static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[0])->Width = (IWDBGrid1->Width/20) * 02; // => Argument out of range
}
//---------------------------------------------------------------------------
I am having the error message "Argument out of range" beginning from the first line and for each line.
Any idea of how to get rid of this error?
Finally, I used a TIWTimer as workaround for going ahead. The result is not perfect, so don’t hesitate to share if you have another solution.
Bellow is the code.
PS : From the beginning it was question of TIWFrame. "TForm1" was a typo.