Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using C++Builder to access columns of TIWDBGrid
#4
(12-20-2022, 09:49 PM)Ibouka Wrote:
(12-20-2022, 08:45 PM)rlebeau Wrote: First off, you are using dynamic_cast incorrectly.  Use static_cast instead.

Second, I'm no IW expert (or even a user!), but it looks like your code may be trying to access the IWDBGrid columns before the ClientDataSet has populated the grid with any data.  Have you tried hooking up the ClientDataSet to the IWDBGrid before executing the REST request?

@ Remy, thank you so much for the suggestion. I tried, but no success.

[font=Consolas, "Courier New", monospace]Greetings!
Finally, I used a TIWTimer as workaround for going ahead. The result is not perfect, so don’t hesitate to share I you have another solution.
Bellow is the code.
PS : From the beginning it was question of TIWFrame. "TForm1" was a typo.[/font]

Code:
__fastcall TIWFrame1::TIWFrame1(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;

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();

IWTimer1->Interval = 100;
IWTimer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TIWFrame1::IWTimer1Timer(TObject *Sender)
{//
IWTimer1->Enabled = false;

static_cast<TIWDBGridColumn*>(IWDBGrid1->Columns->Items[0])->Width = (IWDBGrid1->Width/20) * 02;
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";
}
//---------------------------------------------------------------------------
Reply


Messages In This Thread
RE: Using C++Builder to access columns of TIWDBGrid - by Ibouka - 03-03-2023, 01:11 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)