unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OmniXML, ComCtrls, StdCtrls;
type
TForm1 =
class(TForm)
Tabelle: TListView;
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Button2: TButton;
Button3: TButton;
Button4: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
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);
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
id:
String;
node: IXMLNode;
begin
id := Tabelle.Items[Tabelle.ItemIndex].Caption;
node := XMLDoc.documentElement.selectSingleNode('
prowo/daten'+id);
if node =
nil then showmessage('
is da');
node.selectSingleNode('
daten').text := '
Hallo';
XMLDoc.save(AppPath + '
database.xml');
UpdateList;
end;
end.