|
Introduction
This example source code shows you how to get the list of available graphs within the OCX and how you can fill
dropdown lists so that the user can
select which graph they would like to
view. You should display two dropdown
lists for the users, one showing
GraphTypes such as Height, Weight or
BMI. The second one shows the available
AgeRanges for this specific graph. For
example a Height graph could be
available in two different age ranges
(Birth-36 months and Birth-Adult age).
Note! Remember to set the default graph in the dropdown after filling the dropdown list. An alternative would be to set the default graph (age range) depending on the current age of the patient.
|
| Source code example (When application/graph is started): |
procedure
TMyApplication.UpdateDropdownOfGraphTypes;
//Fills up a
dropdown list showing available
GraphTypes.
//You only need to call this procedure
once.
var
i : integer;
begin
//Fill a dropdown with a list of available
GraphTypes in OCX
With GrowthChart.GraphAttributes do
begin
DropDownListOfGraphsTypes.Items.Clear;
//Scroll through
GraphTypesList to get the names of
//the available graphs.
For i := 0 to
GraphTypesList.Count-1 do
DropDownListOfGraphsTypes.Items.Add(GraphTypesList.Names[i]);
//Select first graph
DropDownListOfGraphsTypes.ItemIndex := 0;
end;
end;
procedure TMyApplication.UpdateDropdownOfAgeRanges;
//Fills up a
dropdown list showing available
AgeRanges for the current GraphType.
//You need to
call this procedure each time you change
GraphType.
var
i : integer;
begin
//Fill a dropdown with a list of available
AgeRanges (for this GraphType) in OCX
With GrowthChart.GraphAttributes do
begin
DropDownListOfAgeRanges.Items.Clear;
//Scroll through AgeRangesList to get the names of
//the available graphs.
For i := 0 to AgeRangesList.Count-1 do
DropDownListOfAgeRanges.Items.Add(AgeRangesList.Names[i]);
//Select first graph
DropDownListOfAgeRanges.ItemIndex := 0;
end;
end;
procedure TMyApplication.OnCreate(Sender: TObject);
//Put this code in the appropriate place when the graph is
created
begin
//Fill a dropdown with a list of available graphs in OCX
UpdateDropdownOfGraphTypes;
UpdateDropdownOfAgeRanges;
end;
|
| |
|
| Source code example (When user selects in
the GraphTypes dropdown list): |
procedure
TMyApplication.DropDownListOfGraphTypesChange(Sender: TObject);
begin
//Update GraphType
only if we have selected a new type
if DropDownListOfGraphTypes.ItemIndex <>
GrowthChart.GraphAttributes.GraphType then
begin
GrowthChart.GraphAttributes.GraphType :=
DropDownListOfGraphsTypes.ItemIndex;
//Call ApplyAttributes after changing one or more GraphAttributes,
//although in this case we only changed one attribute.
GrowthChart.GraphAttributes.ApplyAttributes;
UpdateDropdownOfAgeRanges;
end;
end;
|
| |
|
| Source code example (When user selects in
the AgeRanges dropdown list): |
procedure
TMyApplication.DropDownListOfAgeRangesChange(Sender: TObject);
begin
//If we have selected a valid item in the list set the new age range
if DropDownListOfAgeRanges.ItemIndex <>
GrowthChart.GraphAttributes.AgeRange
then
begin
GrowthChart.GraphAttributes.AgeRange := DropDownListOfAgeRanges.ItemIndex;
//Call ApplyAttributes after changing one or more GraphAttributes,
//although in this case we only changed one attribute.
GrowthChart.GraphAttributes.ApplyAttributes;
end;
end;
|