Selection Changed Event in TreeviewUsing Delphi - delphi

I have one doubt i doing one delphi application.If i select the treeview node at run time display the form in every selected nodes.how its work?.please help me

In Tree View Component, Every node was represented by TTreeNode object, this object has index of selected node, text, etc..
If you want to show form for every node double click
just add the following code
if Treeview1.Selected.Text = 'first_form' then
begin
TFirst_Form.create(Application)
TFirst_Form.show
end;

Related

Refresh one row in cxGrid

I have seen there is a problem refreshing only current row if the data are changed in another form (and DataSet too) or even if the data are changed on server side (in trigger or from another user).
So i find solution that partially work with DevExpress's cxGrid and have following issue.
frm:=TfrmEdb01.Create(Self); // create edit-form
try
frm.LoadData(0); // do the insert in TAdQuery
frm.ShowModal; // Show edit form
// after closing an Edit-Form, make a new record in cxGrid
row:=tv01.dataController.InsertRecord(tv01.Controller.FocusedRecordIndex);
// for each column in grid...
for col:=0 to tv01.DataController.ItemCount-1 do
begin
// ...get its FieldName
sFld:=tv01.DataController.GetItemFieldName(col);
// and if this field exist in edit-form's Query
if frm.q01.FindField(sFld)<>nil then
//then assign this value to the newly created row in the grid.
tv01.DataController.Values[row,col]:=frm.q01.FieldByName(sFld).Value;
end;
finally
frm.Free;
end;
And realy, when I step out from the edit-form there is a New row created in the cxGrid. Problem is in that:
- if is double-clicked (to open edit-form again) then the previous record is opened. It seems to me the Data acctualy did not updated in Query object, only in GridView... maybe I should use values from Grid instead of Query object.
- if select another record (scroll them up and down), and then want to select again this new record, then it can not be focused at all. Only if I reload whole dataSet, then this new record can be selected same as any other.
Cheers!
p.s. To clearify a problem, I will provide whole test-project. There is also SQL script to create a table in the database, and AnyDac connection must be set to Your database.
There is also an image thate will/should ilustrate a problem.
You have call post to save the changes to the underlying dataset. Do it just before finally.
tv01.DataController.Post();
See the help for TcxCustomDataController.Post for more details.

How to extract Object of a BindSource in Delphis LiveBindings?

In Delphi 10.1 I have an ObjectList named DogCollection
and each entry is of the type TDog, a custom class.
thanks to tutorials from malcolm groves I was able to populate a Stringgrid
with my DogCollection.
http://www.malcolmgroves.com/blog/?p=1084
Now I'd like to be able to scroll through the stringgrid and everytime I scroll I want to update the variable "CurrentDog" from the type TDog, with whatever Object is highlighted in the stringgrid.
So I have an Overview about my DogObjects and also a single Object of my Dog
which I can independently view/manipulate.
I am out of ideas at this point.
If it is of any help to you, I can also not get the AfterScroll events of the Adapter to trigger, not even when I add a Navigator with RightClick->Add Navigator.
I thank you for your help and time.
Not sure to understand the question but I think you don't need to have a variable "CurrentDog" to work on the selected object of your list.
You can create all the components (TEdit) you need for your dog (Name, Age...) and bind these components to the same fields (Name, Age...) in your TDataGeneratorAdapter (which is linked to the "Adapter" property of your TAdapterBindSource).
Then, when you select a row in your grid, the corresponding object appears in your edit components. When you modify the "Text" properties, the grid is updated.
EDIT : InternalAdapter
After few searches, you can get your object with the InternalAdapter of your TAdapterBindSource
On the OnClick event :
procedure TForm1.Button1Click(Sender: TObject);
var
Adapter: TBindSourceAdapter;
begin
Adapter:= AdapterBindSource1.InternalAdapter;
CurrentDog:= TDog(Adapter.Current);
end;

Sort TListBox Items Alphabetically in Delphi 7

I am attempting to trigger a sort on the items within a TListBox control after adding/editing entries.
I see that there is a Sorted property which I've set to true, however, this doesn't dynamically sort the ListBox every time I make a change to the contents. There doesn't seem to be any Sort procedure or function available and calling Update or Refresh does not have the desired effect.
I've reached the stage where I'm considering pulling the contents of the ListBox into a TStringList object, sorting that and then putting everything back into the ListBox again. This seems a bit insane though, surely I am overlooking some better method.
Here's an example of changing an existing item:
myListBox.Items[myIndex] := newString; // Update Text
myListBox.Items.Objects[myIndex] := TObject(my_object); // Update associated object
I would expect the control to update to keep things sorted alphabetically but it doesn't.
The sorted property of a list box is actually backed by the Win32 list box style LBS_SORT. That will sort the list box when a new item is added. But it will not do so when an existing item is modified.
So the easy way to work around this is to set Sorted to True, then, instead of modifying existing values, remove the old value and add the new one. So your code would become:
myListBox.Items.Delete(myIndex);
myListBox.Items.AddObject(newString, TObject(my_object));
And if you think about it, your code would have been doomed to failure if the list box behaved the way you expected it to. Because after you modified the text of the item, if the list was re-sorted then myIndex would no longer refer to the same item.

associate a row of a list box with a row of a DB table

How can i associate a row of a list box with a row of a DB table?
I created a firemonky mobile application. On the form i drop a listbox. The listbox is filled with an item from a database.
zQuery1.Close;
ZQuery1.Open;
ListBox1.Items.Clear;
While not ZQuery1.Eof do
Begin
ListBox1.Items.Add(ZQuery1.Fields[1].AsString);
ZQuery1.Next;
end;
ZQuery1.Close;
Displayed is the name of a person.
Now when i doubleclick on the name of the person i want the open a second form with detailed information from that person (available in record). Can someone help me if this can be done?
I want to create an app on iPad so when someone taps on the detail button in the listbox there is more information of that person.
Instead of using listbox.items.add, you need to use listbox.items.addobject. For the purposes of the code below, I am assuming that the primary key of the table will be returned in zquery1.fields[0].
zQuery1.Close;
ZQuery1.Open;
ListBox1.Items.Clear;
While not ZQuery1.Eof do
Begin
ListBox1.Items.AddObject (ZQuery1.Fields[1].AsString,
tobject (zquery1.fields[0].asinteger)
ZQuery1.Next;
end;
ZQuery1.Close;
In order to access the stored id, you would write something like this
avariable:= longint (listbox1.Items.Objects[listbox1.itemindex]);

Wix: ListBox value limitation

Value field in ListBox table has String[64] type. Is there posible to expand this 64-characters limitation? I need to store some directory pathes there.
It's probably (never tried) possible in WiX to override the default schema of he ListBox table. I know in InstallShield I just go to the direct editor and adjust it. WiX has a template schema that is used to build the MSI and you might be able to use the Table element to redefine it. Or it might just give you an error message saying you are defining a well known table.
However, I'm not sure if there would be any side effects in the ListBox control if you exceed 64 char. I don't see anything in the MSI SDK saying what's allowed so I guess your milage may vary.
Here's a trick that you might like though. It's called the evil twin dialog trick. See, in MSI there's a bug that UI elements don't refresh very well and this trick works around it. Consider this:
Dialog1 with ListBox associated to property TESTPROP and Items One value 1 and Two value 2.
Textlabel that displayes [TESTPROP].
When start the dialog the text label is empty after clicking a row in the listbox. Click back and next and suddenly it has the expected text of 1 and 2.
Now create a clone of this dialog ( Dialog2 ) and put a control event on the Listbox of dialog1 that says NewDialog Dialog2 condition=1 and put a control event on the Listbox of dialog2 that says NewDialog Dialog1 condition = 1
Now when you run it the screen refreshes ( although with a big of an ugly flicker ) See it looks like it's the same dialog only it's really the evil twin dialog that's being transitioned to so that the data refreshes correctly.
Now for extra credit use your custom actions to do something like this
ListBox Item 1 Text C:\Pro...Foo\Bob value LISTBOXDIRPROP1
ListBox Item 2 Text C:\Pro...Foo\Ed value LISTBOXDIRPROP2
Property LISTBOXDIRPROP1 = C:\Program Files\Foo\Bob
Property LISTBOXDIRPROP2 = C:\Program Files\Foo\Ed
Then set your TextLabel to display [[TESTPROP]]. This tells it to get deference the value of the value of the property. In other words, TESTPRO = LISTBOXDIRPROP1 = C:\Proggram Files\Foo\Bob
This trick would allow you to display a line that fits the 64 char constraint yet gives additional information when the user selects it.

Resources