Call Onclick event for cxGrid Navigator buttons - delphi

How does one Call the Onclick event for cxGrid Navigator buttons? I can't seem to find it.
Screenshot below...
Thanks,

In the following example View is the TcxGridDBTableView owning the Navigator:
The Navigator Buttons are exposed via a property on View called NavigatorButtons. NavigatorButtons is of type TcxNavigatorControlButtons
On TcxNavigatorControlButtons you'll find all you buttons:
TcxNavigatorControlButtons = class(TcxCustomNavigatorButtons)
...
published
property ConfirmDelete;
property CustomButtons;
property Images;
property First;
property PriorPage;
property Prior;
property Next;
property NextPage;
property Last;
property Insert;
property Append;
property Delete;
property Edit;
property Post;
property Cancel;
property Refresh;
property SaveBookmark;
property GotoBookmark;
property Filter;
end;
So if you want to click on the "Next" button you could write
View.NavigatorButtons.Next.Click;
IF and only IF the button is enabled then the OnClick event will fire.
There are 16 buttons, each one defined byt it's own index:
const
NavigatorButtonCount = 16;
NBDI_FIRST = 0;
NBDI_PRIORPAGE = 1;
NBDI_PRIOR = 2;
NBDI_NEXT = 3;
NBDI_NEXTPAGE = 4;
NBDI_LAST = 5;
NBDI_INSERT = 6;
NBDI_APPEND = 7;
NBDI_DELETE = 8;
NBDI_EDIT = 9;
NBDI_POST = 10;
NBDI_CANCEL = 11;
NBDI_REFRESH = 12;
NBDI_SAVEBOOKMARK = 13;
NBDI_GOTOBOOKMARK = 14;
NBDI_FILTER = 15;
If you prefer you can ude this index to click a certain button:
View.NavigatorButtons.ClickButton(NBDI_EDIT);
Hope this answers your question.

Related

Dynamically add panel control to a dynamic tabsheet (C++ Builder Rad Studio)?

I have a problem getting the tabPage->Name value, because it will generate when user click the button, first block of my code will create new tabsheet inside PageControl3 and then I use the static int tabNumber; by if condition to generate the tabPage->Caption and then I use the caption for tabPage->Name dynamically.
I need the name of that tabsheet to pass it on the Error line.
static int tabNumber;
if (tabNumber >= 1) ++tabNumber;
else tabNumber = 1;
PageControl3->Visible = true;
TTabSheet *tabPage = new TTabSheet(PageControl3);
tabPage->PageControl = PageControl3;
tabPage->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabPage->Name = UnicodeString("ts") + tabPage->Caption;
The second part of my code should create new TPanel inside current tabpage->Name that was created in the above part of my code, BUT it wont work.
TPanel *panelPage = new TPanel(tabPage->Name); // Error Line
panelPage->Align = alClient;
panelPage->Name = UnicodeString("panel") + tabPage->Caption;
Error massage:
[bcc32 Error] mainUnit.cpp(50): E2285 Could not find a match for 'TPanel::TPanel(const UnicodeString)'
So I not know how to access the tabPage->Name value, because that was create dynamically?
DB Baxter The constructor requires a component variable/object and not a string with the text of the name. Such as TPanel *panelPage = new TPanel(tabPage); Will that work for you? Do you need to make the panel's parent tabPage?
By helping DB Baxter, I think the correct and complete answer for create dynamic TPanel inside the dynamic TTabSheet will requires a component variable/object and then for displaying the TPanel we should use the whatever->show(); command, the full code can bee like this:
static int tabNumber = 0;
if (tabNumber >= 1) {
++tabNumber;
} else {
tabNumber = 1;
PageControl3->Visible = true;
}
// create new tab sheet inside PageControl3
TTabSheet *tabSheet = new TTabSheet(PageControl3);
tabSheet->PageControl = PageControl3;
tabSheet->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabSheet->Name = UnicodeString("ts") + tabSheet->Caption;
// create new panel inside the current tab sheet
TPanel *panelBox = new TPanel(tabSheet);
panelBox->Parent = tabSheet;
panelBox->Align = alClient;
panelBox->Name = UnicodeString("panelPage") + IntToStr(tabNumber);
panelBox->BevelOuter = bvNone;
panelBox->ShowCaption = true;
panelBox->Caption = UnicodeString("panel") + tabSheet->Caption;
panelBox->Show();
I hope this code can help anyone to generate the dynamic tab sheet with panel, by the way if you want add some frame to it the following code should use:
// adding the registration frame to the panel
TregFrame *newRegistration = new TregFrame(panelBox);
newRegistration->Parent = panelBox;
newRegistration->Align = alClient;
Note: don't forget to include your frame in your working file, for example #include "registrationFrame.h".

How To Set Addapted PassData Between Activities?

i am trying to create a dynamic list of buttons and every button create a passed data to another activity that show the relative buttons detile.
the code i used is here:
for (int i = 0; i < size; i++)
{
temp = new Button(this);
temp.SetText(data[i].Name, TextView.BufferType.Normal); //arbitrary task
numArrey[i] = i;
main_linearScroller.AddView(temp);
tv[i] = temp;
tv[i].SetTextSize(Android.Util.ComplexUnitType.Dip, 20);
tv[i].SetBackgroundResource(Resource.Drawable.textbox_back1);
Display d = WindowManager.DefaultDisplay;
int width = d.Width;
int height = d.Height;
tv[i].SetHeight(10);
tv[i].SetWidth(width);
tv[i].Click += (sender,e)=>
{
var detileListShow = new Intent(this, typeof(DetileListShow));
detileListShow.PutExtra("Data", i);
Console.WriteLine("Starting Activity With Data{0}", i);
StartActivity(detileListShow);
};
every thing is good untile last parag that i setting tv[i].click.
every buttons.PutExtera = 21.
how can i fix it?
i think it's better every buttons can save the value that need to return but i dont know how...

FastReport (RAD Studio XE7 C++ Builder) - How do you create a sum formula?

I am using Embarcadero RAD Studio XE7, C++ Builder with FastReport 5. I create a very simple FastReport that adds up some values in a table and prints out a total. I cannot get the syntax for the sum formula correct, and as a result it keeps throwing an access violation error.
To reproduce this problem in RAD Studio XE7:
Open RAD Studio XE7 and go to File -> New -> VCL Forms Application - C++Builder
Drag a TClientDataSet component named ClientDataSet1 onto the form. Drag a TfrxReport component named frxReport1 onto the form. Drag a TfrxDBDataset named frxDBDataset1 onto the form.
Drag a TButton named Button1 onto the form, and double-click it to create an OnClick event handler.
Add the following lines to the Button1Click event handler:
// Create a simple dataset.
ClientDataSet1->FieldDefs->Clear();
ClientDataSet1->FieldDefs->Add("ID", ftInteger, 0, false);
ClientDataSet1->FieldDefs->Add("Status", ftString, 10, false);
ClientDataSet1->FieldDefs->Add("Created", ftDate, 0, false);
ClientDataSet1->FieldDefs->Add("Volume", ftInteger, 0, false);
try
{
ClientDataSet1->CreateDataSet();
}
catch(Exception& e)
{
ShowMessage("ERROR: '" + e.Message + "'");
return;
}
ClientDataSet1->Open();
for (int i = 0; i < 10; ++i)
{
ClientDataSet1->Append();
ClientDataSet1->FieldByName("ID")->AsInteger = i;
ClientDataSet1->FieldByName("Status")->AsString = "Code" + String(i);
ClientDataSet1->FieldByName("Created")->AsDateTime = Now();
ClientDataSet1->FieldByName("Volume")->AsInteger = Random(1000);
try
{
ClientDataSet1->Post();
}
catch(Exception& e)
{
ShowMessage("ERROR: '" + e.Message + "'");
ClientDataSet1->Close();
return;
}
}
// Dataset created successfully, now create Fast Report that outputs that dataset
frxReport1->Clear();
frxDBDataset1->DataSet = (TDataSet*)ClientDataSet1;
frxReport1->DataSets->Add(frxDBDataset1);
TfrxDataPage* DataPage = new TfrxDataPage(frxReport1);
DataPage->CreateUniqueName();
TfrxReportPage* Page = new TfrxReportPage(frxReport1);
Page->CreateUniqueName();
// set sizes of fields, paper and orientation to defaults
Page->SetDefaults();
Page->Orientation = poPortrait;
TfrxReportTitle* HeaderBand = new TfrxReportTitle(Page);
HeaderBand->CreateUniqueName();
HeaderBand->Top = 0;
HeaderBand->Height = 20;
TfrxMemoView* Memo = new TfrxMemoView(HeaderBand);
Memo->CreateUniqueName();
Memo->Text = "Generic Report";
Memo->SetBounds(0, 0, 200, 20);
TfrxHeader* ColumnHeaderBand;
ColumnHeaderBand = new TfrxHeader(Page);
ColumnHeaderBand->CreateUniqueName();
ColumnHeaderBand->Top = HeaderBand->Top + HeaderBand->Height;
ColumnHeaderBand->Height = 20;
TfrxMasterData* DataBand = new TfrxMasterData(Page);
DataBand->Name = "DataBand";
DataBand->DataSet = frxDBDataset1;
DataBand->Top = ColumnHeaderBand->Top + ColumnHeaderBand->Height;
DataBand->Height = 20;
TfrxMemoView* mField;
for (int i = 0; i < DataBand->DataSet->FieldsCount(); ++i)
{
const String fieldname = ClientDataSet1->Fields->Fields[i]->FieldName;
mField = new TfrxMemoView(ColumnHeaderBand);
mField->CreateUniqueName();
mField->SetBounds(i * 100, 0, 100, 20);
mField->Text = fieldname;
mField->HAlign = haCenter;
// Now do the actual data
mField = new TfrxMemoView(DataBand);
mField->CreateUniqueName();
mField->DataSet = DataBand->DataSet;
mField->DataField = fieldname;
mField->SetBounds(i * 100, 0, 100, 20);
mField->HAlign = haRight;
}
// Now do footer band. This will hold the total
TfrxBand* FooterBand = new TfrxFooter(Page);
FooterBand->CreateUniqueName();
FooterBand->Top = DataBand->Top + DataBand->Height;
FooterBand->Height = HeaderBand->Height;
TfrxMemoView* totals = new TfrxMemoView(FooterBand);
totals->Top = 0;
totals->Left = 0;
totals->Height = 20;
totals->Align = baWidth;
bool is_error = false;
try
{
// ALL OF THESE LINES CAUSE THE ACCESS VIOLATION
// Create a summation function that displays the volume total
totals->Text = "Totals: [Sum(<ClientDataSet1.Volume>, MyDataBand, 1)]";
//totals->Text = "Totals: [Sum(<ClientDataSet1.'volume'>,MyDataBand,1)]";
//totals->Text = "Totals: [Sum(<ClientDataSet1.\"volume\">,MyDataBand,1)]";
//totals->Text = "Totals: [Sum(<ClientDataSet1.""volume"">,MyDataBand,1)]";
//totals->Text = "Totals: [Sum(<ClientDataSet1.''volume''>,MyDataBand,1)]";
//totals->Text = "Totals: [Sum(<ClientDataSet1.\'volume\'>,MyDataBand,1)]";
}
catch(Exception& e)
{
ShowMessage("ERROR: '" + e.Message + "'");
is_error = true;
}
if (!is_error)
{
frxReport1->ShowReport(true);
}
ClientDataSet1->Close();
ShowMessage("Program complete!");
Compile and run the program. The code in the try block will throw an access violation. Why is this happening? What is the correct syntax to create the sum formula?
UPDATE:
I modified the code by explicitly setting a name for frxDBDataset1:
frxReport1->Clear();
frxDBDataset1->DataSet = (TDataSet*)ClientDataSet1;
frxDBDataset1->Name = "frxDBDataset1"; // line added
frxReport1->DataSets->Add(frxDBDataset1);
I also changed the formula line to the following:
totals->Text = "Totals: [Sum(<frxDBDataset1.\"Volume\">, DataBand, 1)]";
I am still getting the access violation, though.
I was able to run without problems the following linked example, which includes the modifications we commented before.
https://www.dropbox.com/s/6grmajvoy9ijxfh/SO_test1.7z?dl=0
Go to Project --> Options --> Packages --> Runtime Packages. Set "Link with Runtime Packages" to False.
The default for this option is True for C++Builder, False for Delphi. This explains why the equivalent code worked in Delphi, but didn't work in C++Builder.

Can we use some kind of array to control the fields on the form?

I have a asp.net form with 20 textbox controls(VB2012 and 2008R2). Is there an array function for me to change the property of all the fields or do I have to spell it out separately. Example changing the back color and making the control editable when the edit button is clicked.
Thanks
~ Nita
I did this sometime ago:
void SetEnabled(bool enable)
{
textBox1.enabled = enable;
textBox1.enabled = enable;
textBox2.enabled = enable;
textBox3.enabled = enable;
textBox4.enabled = enable;
textBox5.enabled = enable;
... repeat until textBox20
textBox20.enabled = enable;
}
to call it, for example:
SetEnabled(true);
or
SetEnabled(false);

Adding new elements to an enumerated type

Given an enumerated type declaration in Delphi such as:
TMyType = (Item1, Item2, Item3);
is there any way to add a fourth item, say Item4, to the enumerate type at runtime so that
at some point during the application's execution I have:
TMyType = (Item1, Item2, Item3, Item4);
Or are types fixed in Delphi?
You can create a set.
The following example initializes the set with items item1 and item4.
After that item5 is added.
It shows whether item5 is in the set, before and after adding, so you'll get this output:
FALSE
TRUE
Example:
program Project1;
{$APPTYPE CONSOLE}
uses SysUtils;
type
TMyType = (Item1, Item2, Item3, Item4, Item5,Item6);
const
cItems1And4 : set of TMyType = [Item1,Item4];
var
MyItems:set of TMyType;
begin
MyItems := cItems1And4;
WriteLn(Item5 in MyItems);
Include(MyItems,Item5);
WriteLn(Item5 in MyItems);
ReadLn;
end.
...
I wanted to type the following as a comment to Andreases reply, but the comment system doesn't let me properly format stuff..
If you're not stuck with an ancient Delphi, this is probably a better idea:
TComputerType = record
const
Desktop = 0;
Server = 1;
Netbook = 2;
Tabled = 3;
end;
That makes sure you don't pollute your namespace, and you'll get to use it as if it's a scoped enum:
TComputerType.Netbook
I usually do it like that nowadays.. You can even create some handy helper-functions or properties in there, for example to convert from and to strings.
No, you 'can't' do this. It is against the way Delphi works. (Recall that Delphi checks your types already at compile time.)
If I were you, I'd not do
TComputerType = (ctDesktop, ctServer, ctLaptop, ctNetbook, ctTablet)
Instead, I'd do
TComputerType = integer;
const
COMPUTER_TYPE_DESKTOP = 0;
COMPUTER_TYPE_SERVER = 1;
COMPUTER_TYPE_LAPTOP = 2;
COMPUTER_TYPE_NETBOOK = 3;
COMPUTER_TYPE_TABLET = 4;
I am sure you get why.
Types are fixed at compile time in Delphi—it is, after all, a statically typed language.
You can, at compile time, define subranges of an enumeration:
type
TEnum = (item1, item2, item3, item4);
TSubRangeEnum = item1..item3;
Since I cannot yet comment, I will add one addendum to what Andreas suggested that might help if you have many such lists to maintain. Adding a "base" constant for each grouping might help keep them better organized within your code and help with debugging the constants later (assuming each group has a unique base, of course).
TComputerType = integer;
const
COMPUTER_TYPE_BASE = 100;
COMPUTER_TYPE_DESKTOP = COMPUTER_TYPE_BASE + 1;
COMPUTER_TYPE_SERVER = COMPUTER_TYPE_BASE + 2;
COMPUTER_TYPE_LAPTOP = COMPUTER_TYPE_BASE + 3;
COMPUTER_TYPE_NETBOOK = COMPUTER_TYPE_BASE + 4;
COMPUTER_TYPE_TABLET = COMPUTER_TYPE_BASE + 5;

Resources