unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OmniXML, ComCtrls, StdCtrls, StrUtils, Menus;
type
TForm1 =
class(TForm)
Tabelle: TListView;
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Button2: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
MainMenu1: TMainMenu;
Datei1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure UpdateList;
procedure TabelleColumnClick(Sender: TObject; Column: TListColumn);
procedure TabelleCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer;
var Compare: Integer);
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
XMLDoc: IXMLDocument;
AppPath:
string;
ColumnToSort: Integer;
LastSorted: Integer;
SortDir: Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
AppPath := ExtractFilePath(Application.ExeName);
XMLDoc := CreateXMLDoc;
XMLDoc.DocumentElement := XMLDoc.CreateElement('
daten');
if not FileExists(AppPath+'
database.xml')
then begin
XMLDoc.loadXML('
<?xml version="1.0" encoding="ISO-8859-1"?><Daten></Daten>');
end else
XMLDoc.load(AppPath+'
database.xml');
if XMLDoc.parseError.errorCode <> 0
then begin
MessageDlg('
Die XML Datei ist nicht korrekt!' + #13#10
+ '
Das Programm wird nun beendet!', mtError, [mbOK], 0);
Application.Terminate;
end;
UpdateList;
end;
procedure TForm1.UpdateList;
var
daten: IXMLNodeList;
subNode: IXMLNode;
i: integer;
begin
Tabelle.Items.Clear;
Tabelle.Items.BeginUpdate;
daten := XMLDoc.documentElement.selectNodes('
daten');
for i:=0
to daten.length -1
do begin
subNode := daten.item[i].selectSingleNode('
name');
Tabelle.Items.Add;
Tabelle.Items[i].Caption := subNode.Text;
with Tabelle.Items[i].SubItems
do begin
subNode := daten.item[i].selectSingleNode('
klasse');
if subNode <>
nil then
Add(subNode.Text);
subNode := daten.item[i].selectSingleNode('
projekt1');
if subNode <>
nil then
Add(subNode.Text);
subNode := daten.item[i].selectSingleNode('
projekt2');
if subNode <>
nil then
Add(subNode.Text);
end;
end;
Tabelle.Items.EndUpdate;
end;
procedure TForm1.TabelleColumnClick(Sender: TObject; Column: TListColumn);
begin
ColumnToSort := Column.
Index;
if ColumnToSort = LastSorted
then
SortDir := 1 - SortDir
else
SortDir := 0;
LastSorted := ColumnToSort;
(Sender
as TCustomListView).AlphaSort;
end;
procedure TForm1.TabelleCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer;
var Compare: Integer);
var
ix: Integer;
begin
if ColumnToSort = 0
then
begin
if SortDir = 0
then
Compare := CompareText(Item1.Caption,Item2.Caption)
else
Compare := CompareText(Item2.Caption,Item1.Caption);
end //if ColumnToSort = 0 then
else
begin
ix := ColumnToSort - 1;
if SortDir = 0
then
Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix])
else
Compare := CompareText(Item2.SubItems[ix],Item1.SubItems[ix]);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
node: IXMLNode;
daten: IXMLNodeList;
i: integer;
begin
node :=
nil;
daten := XMLDoc.DocumentElement.SelectNodes('
daten/name');
for i := 0
to daten.Length - 1
do
if(Tabelle.Selected.Caption = daten.Item[i].Text)
then
begin
node := daten.Item[i].GetParentNode;
break;
end;
if(node <>
nil)
then
begin
ShowMessage(node.XML);
node.selectSingleNode('
projekt1').text := ComboBox1.Text;
UpdateList;
end;
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
daten: IXMLNodeList;
subNode: IXMLNode;
i, j: integer;
begin
j := 0;
Tabelle.Items.Clear;
Tabelle.Items.BeginUpdate;
daten := XMLDoc.documentElement.selectNodes('
daten');
for i:=0
to daten.length -1
do begin
subNode := daten.item[i].selectSingleNode('
name');
If (SoundEx(subNode.Text,2) = SoundEx(Edit1.Text,2))
then
begin
Tabelle.Items.Add;
Tabelle.Items[j].Caption := subNode.Text;
with Tabelle.Items[j].SubItems
do begin
subNode := daten.item[i].selectSingleNode('
klasse');
if subNode <>
nil then
Add(subNode.Text);
subNode := daten.item[i].selectSingleNode('
projekt1');
if subNode <>
nil then
Add(subNode.Text);
subNode := daten.item[i].selectSingleNode('
projekt2');
if subNode <>
nil then
Add(subNode.Text);
end;
j := j+1;
end;
end;
Tabelle.Items.EndUpdate;
end;
procedure TForm1.Edit2Change(Sender: TObject);
var
daten: IXMLNodeList;
subNode: IXMLNode;
i, j: integer;
begin
j := 0;
Tabelle.Items.Clear;
Tabelle.Items.BeginUpdate;
daten := XMLDoc.documentElement.selectNodes('
daten');
for i:=0
to daten.length -1
do begin
subNode := daten.item[i].selectSingleNode('
name');
If (subNode.Text = Edit2.Text)
then
begin
Tabelle.Items.Add;
Tabelle.Items[j].Caption := subNode.Text;
with Tabelle.Items[j].SubItems
do begin
subNode := daten.item[i].selectSingleNode('
klasse');
if subNode <>
nil then
Add(subNode.Text);
subNode := daten.item[i].selectSingleNode('
projekt1');
if subNode <>
nil then
Add(subNode.Text);
subNode := daten.item[i].selectSingleNode('
projekt2');
if subNode <>
nil then
Add(subNode.Text);
end;
j := j+1;
end;
end;
Tabelle.Items.EndUpdate;
end;
end.