unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Menus, msxml2_tlb;
type
TMainFrm =
class(TForm)
MainMenu1: TMainMenu;
Datei1: TMenuItem;
Beenden1: TMenuItem;
Film1: TMenuItem;
Hinzufgen1: TMenuItem;
Entfernen1: TMenuItem;
N1: TMenuItem;
Bearbeiten1: TMenuItem;
N2: TMenuItem;
Info1: TMenuItem;
StatusBar1: TStatusBar;
MovieList: TListView;
procedure FormCreate(Sender: TObject);
procedure UpdateList;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
fAppPath:
string;
end;
const
DATABASE_FNAME ='
movies.xml';
var
MainFrm: TMainFrm;
xmlDoc: IXMLDOMDocument2;
implementation
{$R *.DFM}
procedure TMainFrm.FormCreate(Sender: TObject);
begin
fAppPath := ExtractFilePath(Application.Exename);
XmlDoc := CoDomDocument40.Create;
XmlDoc.SetProperty('
NewParser', true);
if not FileExists(fAppPath + DATABASE_FNAME)
then begin
XmlDoc.loadXml('
<?xml version="1.0"?><movieorganiezer></movieorganiezer>');
end else
XmlDoc.load(fAppPath + DATABASE_FNAME);
if XmlDoc.parseError.errorCode <> 0
then begin
MessageDlg('
Die XML Datei ist nicht korrekt!' + #13#10
+'
Das Programm wird nun beenden!', mtError, [MbOk], 0);
Application.Terminate;
end;
if XmlDoc.documentElement.nodeName <> '
movieorganiezer'
then
Application.Terminate;
end;
procedure TMainFrm.UpdateList;
const
NAMES:
array[0..2]
of string = ('
name', '
format', '
ton');
var
movies: IXMLDOMNodeList;
subNode: IXMLDOMNode;
i, j: integer;
begin
MovieList.Items.Clear;
MovieList.Items.BeginUpdate;
movies := xmlDoc.documentElement.selectNodes('
movie');
for i:=0
to movies.length - 1
do begin
subNode := movies.item[i].selectSingleNode('
id');
MovieList.Items.Add;
MovieList.Items[i].Caption := subnode.text;
with Movielist.Items[i].SubItems
do begin
for j:=0
to length(NAMES[-1])
do begin
subNode := movies.item[i].selectSingleNode(Names[j]);
if subNode <>
nil then
Add(subNode.text)
else
Add('
');
end;
end;
end;
MovieList.items.endupdate;
end;
end.