Delphi-PRAXiS
Seite 13 von 35   « Erste     3111213 141523     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Software-Projekte der Mitglieder (https://www.delphipraxis.net/26-software-projekte-der-mitglieder/)
-   -   himXML (gesprochen himix ML) (https://www.delphipraxis.net/130751-himxml-gesprochen-himix-ml.html)

himitsu 1. Aug 2009 16:00

Re: himXML (gesprochen himix ML)
 
Liste der Anhänge anzeigen (Anzahl: 3)
vieleicht hat's ja schon wer vor Ewigkeiten entdeckt ... in den Tools zu himXML existiert ja schon seit einigen Monaten soeine nette und bisher mehr "funktionsunfähige" Klasse :oops:

im Zuge einiger anderer Projekte ist diese inzwischen aber gewachsen :angel2:

sie wird z.B. so eingebunden:
Delphi-Quellcode:
Uses OptionsSelect, himXML_Tools;

Procedure TMainForm.FormCreate(Sender: TObject);
  Begin
    _Options := TXMLProjectOptions.Create;
    _Options.AutorOrCompany  := 'FNS Enterprize''s';
    _Options.Project         := 'SearchSameFiles';
    _Options.OptionsVersion  := '1.0';
    _Options.AllowedLocations := [xpoSession, xpoAppDir, xpoLocalAppDataC];
    _Options.FileName        := 'SearchSameFiles.xml';
    _Options.OnSelectLocation := SelectLocation;
    _Options.Open;
    If _Options.Exists('window') Then Begin
      Left  := _Options.Value['window\left'];
      Top   := _Options.Value['window\top'];
      Width := _Options.Value['window\width'];
      Height := _Options.Value['window\height'];
    End;
    If not _Options.Exists('view') Then ComboBox1.ItemIndex := 1
    Else ComboBox1.ItemIndex := _Options.Value['view'];
  End;

Procedure TMainForm.FormDestroy(Sender: TObject);
  Begin
    _Options.Free;
  End;
da ich keinen eigenen Auswahldialog eingebunden hab, falls keine Datei gefunden wurde und eine Location gewählt werden muß,
kommt dann z.B. noch sowas dazu:
dieses nutzt den Dialog aus dem Anhang
Delphi-Quellcode:
Procedure TMainForm.SelectLocation(Sender: TXMLProjectOptions; Var Location: TXMLPOLocation);
  Var OSel: TOptionsSelectForm;
    L:     TXMLPOLocation;
    S, S2: String;

  Begin
    OSel := TOptionsSelectForm.Create(Self);
    Try
      For L := Low(TXMLPOLocation) to High(TXMLPOLocation) do
        If L in Sender.AllowedLocations Then Begin
          Case L of
            xpoSession: Begin
              S := 'session';
              S2 := 'the options are not saved' + sLineBreak + 'and are only valid for this runtime';
            End;
            xpoDirect: Begin
              S := 'direct';
              S2 := 'the location is determined by the program';
            End;
            xpoAppDir: Begin
              S := 'application path';
              S2 := 'the options are saved in the same directory where the program is';
            End;
            xpoLocalAppDataCP, xpoLocalAppDataP, xpoLocalAppDataC, xpoLocalAppData: Begin
              S := 'local application data';
              S2 := 'the options are saved in a directory that serves as a data repository for local (nonroaming) applications';
            End;
            xpoRoamingAppDataCP, xpoRoamingAppDataP, xpoRoamingAppDataC, xpoRoamingAppData: Begin
              S := 'roaming application data';
              S2 := 'the options are saved in a directory that serves as a common repository for application-specific data';
            End;
            xpoAllUserAppDataCP, xpoAllUserAppDataP, xpoAllUserAppDataC, xpoAllUserAppData: Begin
              S := 'all users application data';
              S2 := 'the options are saved in a directory containing application data for all users';
            End;
            Else Begin
              S := 'unknown';
              S2 := 'unknown';
            End;
          End;
          OSel.AddDir(S, Sender.GetPath(L), S2, Ord(L), L = Location);
        End;
      If OSel.ShowModal = mrOk Then Location := TXMLPOLocation(OSel.Tag);
    Finally
      OSel.Free;
    End;
  End;
diese Funktion kann sich ja dann jeder gestalten wie er sill ... selbst eine Auswahl durch das Programm ist hier möglich, falls man den User nicht "nerven" möchte ... meiner Klasse ist es ja egal wie und wo die Auswahl getroffen wird :nerd:

im Beispiel wird einfach eine Form angezeigt, die möglichen/erlaubten Verzeichnisse werden angezeigt und der User darf dann wählen.


ja und so werden dann z.B. in Hier im Forum suchenSearchSameFiles die Einstellungen für den dortigen Verzeichnisauswahldialog geladen:
Delphi-Quellcode:
// auslesen
i2 := _Options.Value['directory\count'];
For i := 0 to i2 - 1 do
  Start.AddDir(_Options.Value[Format('directory\name%d', [i])]);
Start.Edit2.Text       := _Options.Value['mask'];
Start.CheckBox1.Checked := _Options.Value['fullCompare'];
Start.CheckBox2.Checked := _Options.Value['fileCache'];
If Start.ShowModal = mrOk Then Begin
...

// ändern
_Options.BeginUpdate;
_Options.Value['directory\count'] := Length(Dirs);
For i := 0 to High(Dirs) do
  _Options.Value[Format('directory\name%d', [i])] := UTF8ToWideString(Dirs[i]);
_Options.Value['mask']       := UTF8ToWideString(Mask);
_Options.Value['fullCompare'] := Start.CheckBox1.Checked;
_Options.Value['fileCache']  := Start.CheckBox2.Checked;
_Options.EndUpdate;

nötige Dateien sind in der Beta-Version im Post 1# zu finden

und die Klasse selber ist aktuell so aufgebaut
Delphi-Quellcode:
Type TXMLPOLocation  = (xpoSession, xpoDirect, xpoAppDir,
    xpoLocalAppDataCP, xpoLocalAppDataP, xpoLocalAppDataC, xpoLocalAppData,
    xpoRoamingAppDataCP, xpoRoamingAppDataP, xpoRoamingAppDataC, xpoRoamingAppData,
    xpoAllUserAppDataCP, xpoAllUserAppDataP, xpoAllUserAppDataC, xpoAllUserAppData);
TXMLPOLocations      = Set of TXMLPOLocation;
TXMLPOSelectLocation = Procedure(Sender: TXMLProjectOptions; Var Location: TXMLPOLocation) of Object;

TXMLProjectOptions = Class
  Constructor Create;
  Destructor Destroy;

  Property AutorOrCompany:   String;
  Property Project:          String;
  Property OptionsVersion:   String;

  Property AllowedLocations: TXMLPOLocations;
  Property FileName:         TWideString;
  Property Protection:       AnsiString;

  Function ExistingLocations: TXMLPOLocations;
  Function PossibleLocations: TXMLPOLocations;

  Procedure Open;
  Procedure Open   (Location: TXMLPOLocation);
  Property ActiveLocation:   TXMLPOLocation;

  Procedure BeginUpdate;
  Property Value      [Name: String]: Variant;
  Property SerializeObj[Name: String]: TObject;
  Property Protect    [Name: String]: Boolean;
  Function Exists     (Name: String): Boolean;
  Procedure DeleteValue (Name: String);
  Procedure EndUpdate;

  Procedure Save   (Location: TXMLPOLocation; DeleteOther: Boolean);
  Procedure Close;
  Procedure Delete (Location: TXMLPOLocation);
  Procedure DeleteAllOptionFiles;

  Property OnSelectLocation: TXMLPOSelectLocation;

  Function GetPath (Location: TXMLPOLocation): String;

  Property Tag: Integer;
End;

TheJeed 3. Aug 2009 19:01

Re: himXML (gesprochen himix ML)
 
Tolles Projekt - sehr hilfreich! Danke für Deine Mühe und für das Engagement, das Ergebnis öffentlich zur Verfügung zu stellen! :cheers:

xZise 3. Aug 2009 20:27

Re: himXML (gesprochen himix ML)
 
Hallo himitsu,
ein tolles Projekt (auch wenn ich bisher noch nicht nutzen konnte).

Aber ein paar Sachen habe ich da schon.
Als Erstes: Und zwar wozu wurde der RadioButton erfunden? Weil du auf dem Selektionsfenster Buttons verwendest.
Und dann wäre da noch eine Idee: Und zwar die Möglichkeit, eine Default Funktion und eine Try Funktion (Wie StrToIntDef und TryStrToInt).
Und zur Verschlüsselung: Könnte man es einstellen, welche Verschlüsselungsmethode verwendet? Also ein OnEncrypt und OnDecrypt Ereignis?

Zum Zweiten Punkt:
Delphi-Quellcode:
function TXMLProjectOptions.ValueDef(const AName : string; const ADefaultValue : Variant) : Variant;
begin
  if Exists(AName) then
    Result := Value[AName]
  else
    Result := ADefaultValue;
end;

function TXMLProjectOptions.TryValue(const AName : string; out AValue : Variant) : Boolean;
begin
  if Exists(AName) then
  begin
    Result := True;
    AValue := Value[AName]
  end else
    Result := False;
end;
Ob das so geht, weiß ich nicht ;) Aber ich denke, damit dürfte klar sein, was ich damit meinte.

MfG
xZise

himitsu 3. Aug 2009 21:32

Re: himXML (gesprochen himix ML)
 
Zitat:

Zitat von xZise
Als Erstes: Und zwar wozu wurde der RadioButton erfunden? Weil du auf dem Selektionsfenster Buttons verwendest.

DER ist häßlich :tongue:

nja, mir gefiel die Optik mit Buttons einfach besser :angel2:

im Anhang ist mal die aktuelle Version des Dialogs verbaut
- reagiert auf Scrollrad, Pfeiltastentasten und bei Doppelkick direkt als Auswahl
- im Popupmenü (der Trees/Dateilisten) wird der Dialog auch zum Ändern der Position wiederverwendet

ja und fülle mal die RadioGroup mit "vielen" Einträgen ... wird sehr unübersichtlich, wenn die anfängt alles übereinanderzumalen :?
die 3 Auswahlfelder sind nicht alle möglichen Verzeichnisse - hab nicht alles im Programm freigeschaltet - und nun verkleinere mal meinen Dialod in seiner Höhe und schau was passiert :)
(würde ebenfalls geschehen, wenn noch mehr Verzeichnisse zur Wahl stünden)

Aber insgesamt ist es ja halb so schlimm, da du in OnSelectLocation ja einbinden kannst, was DU willst :stupid:



Das mit der Defaultfunktion ist klasse ... warum bin ich da nicht selber draufgekommen :wall:
da mach ich in mein Programm einige if-exists-Abfragen und damit würde das Ganze hübscher aussehn :thumb:

Zitat:

Zitat von xZise
Ob das so geht, weiß ich nicht ;) Aber ich denke, damit dürfte klar sein, was ich damit meinte.

sieht beides OK aus und dürfte auch funktionieren ... wird gleich eingebaut

und daas mit der Verschlüsselung ... da gibt es ja schon was in tXMLFile drin und eigentlich wollte ich das auch durchschleifen (hatte ich wohl wieder vergessen)

[edit]
Testprogramm jetzt im anderem Thread erneuert, drum hier entfernt > siehe dort

BlueStarHH 13. Aug 2009 19:23

Re: himXML (gesprochen himix ML)
 
Hi himitsu,

erstmal Danke für das tolle Projekt! Ich möchte damit meine eigene Ini-Klasse ersetzen. Meine Ini-Klasse macht erstmal genau das selbe wie Deine TXMLIniFile im Constructor. Ich erzeuge eine Instanz und mache nichts anderes. Dann rufe ich diese Methode auf:

XML.RootNode.Nodes.Exists('Nicht\Da\Nein')

Diese gibt dann true zurück, obwol keine Node von mir erzeut wurde. Warum? Ist das ein Fehler?

himitsu 13. Aug 2009 20:29

Re: himXML (gesprochen himix ML)
 
hast du mal ein ausführlicheres Beispiel dafür?

dieses piept jedenfalls nicht.
Delphi-Quellcode:
XML := TXMLFile.Create;
if XML.RootNode.Nodes.Exists('Nicht\Da\Nein') then
  beep;
oder hast du zufällig vorher auf etwas unterhalb dieses Zweiges zugegriffen? (auch lesend)

per Standard (über XML.Options änderbar) werden ja Nodes automatisch erzeugt, wenn man darauf zugreift
Delphi-Quellcode:
S := XML.RootNode.Nodes['Nicht\Da\Nein'].Text;

BlueStarHH 14. Aug 2009 11:15

Re: himXML (gesprochen himix ML)
 
Zitat:

Zitat von himitsu
oder hast du zufällig vorher auf etwas unterhalb dieses Zweiges zugegriffen? (auch lesend)

Ja, das wars! Das hat den Zweig angelegt. Sorry, habe ich übersehen!

himitsu 14. Aug 2009 12:04

Re: himXML (gesprochen himix ML)
 
Zitat:

Zitat von BlueStarHH
Ja, das wars! Das hat den Zweig angelegt. Sorry, habe ich übersehen!

Du kannst das Verhalten, wie gesagt auch abschalten, aber dann würde mindestens NIL für einen Knoten zurückgegeben, welcher nicht existiert und im schlimmsten Falle gäbe es natürlich Probleme, wenn du auf etwas nichtexistierendes zugreifst.

hier würde im Falle, daß xoNodeAutoCreate nicht definiert wäre und z.B. "Da" nicht existiert, bei .Text eine Exception ala "Zugriff auf Adresse $0000000x" auftreten, da ja TXMLNode(nil).Text nicht ginge
Delphi-Quellcode:
S := XML.RootNode.Nodes['Nicht\Da\Nein'].Text;
S := XML.RootNode.Nodes['Nich'].Nodes['Da'].Nodes['Nein'].Text;
beim Letzen wäre die Exception sogar schon bei .Nodes['Nein'], da ja dann Nodes['Da'] das NIL zurückgeben würde.

himitsu 26. Aug 2009 08:59

Re: himXML (gesprochen himix ML)
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hab den Dialog jetzt mit ins Projekt eingefügt, allerdings fehlt dazu noch eine Demo
(aber da gibt's ja weiter oben wenigstens ein paar Beispiele)

Die meißten Änderungen gab es vorallem in den Tools, wo die eine Klasse nun so aussieht:
Delphi-Quellcode:
TXMLProjectOptions = Class
  Constructor Create;
  Destructor Destroy;

  Property AutorOrCompany:    String;
  Property Project:           String;
  Property OptionsVersion:    String;

  Property AllowedLocations:  TXMLPOLocations;
  Property FileName:          TWideString;
  Property Protection:        AnsiString;

  Function ExistingLocations: TXMLPOLocations;
  Function PossibleLocations: TXMLPOLocations;

  Function Open:                               Boolean;
  Function Open    (Location: TXMLPOLocation): Boolean;
  Property ActiveLocation:    TXMLPOLocation;

  Property ReadOnly:          Boolean;

  Procedure BeginUpdate;
  Property Value       [Name: String]:              Variant;
  Property ValueFmt    [Name: String; Fmt: Variant]: Variant;
  Procedure SaveObject  (Name: String;    Value:  TObject);
  Procedure LoadObject  (Name: String;    Value:  TObject);
  Property Protect     [Name: String]: Boolean;
  Function Exists      (Name: String): Boolean;
  Function GetValueDef (Name: String;    Default:          Variant): Variant;
  Function GetValueDef (Name: String;    Default, Min, Max: Variant): Variant;
  Function TryGetValue (Name: String; Var Value:            Variant): Boolean;
  Function TryLoadObject(Name: String;    Value:            TObject): Boolean;
  Procedure DeleteValue (Name: String);
  Procedure EndUpdate;

  Procedure Save    (Location: TXMLPOLocation; DeleteOther: Boolean);
  Procedure Close;
  Procedure Delete  (Location: TXMLPOLocation);
  Procedure DeleteAllOptionFiles;

  Property OnSelectLocation:  TXMLPOSelectLocation;
  Property OnException:       TXMLPOErrorProc;

  Function GetPath (Location: TXMLPOLocation): String;

  Property Tag:               Integer;
End;
Vorallem die ...Def- und Try...-Funktionen würden überarbeitet/erweitert und es gab Änderungen in der Verzeichnisbehandlung.
Delphi-Quellcode:
Self.Left := Options.GetValueDef('window\left', Left);
ComboBox1.ItemIndex := Options.GetValueDef('view', 1, 0, ComboBox1.Items.Count - 1);
Als nächstes wird der SAX-Parser überarbeitet
und es wird eine Umkehrklasse dazu entstehen, also so das man auch sehr sehr große XML-Dateien effektiv erstellen kann.

[add]
Delphi-Quellcode:
Options.ValueFmt['directory\name%d', i]
hatte ich vergessen zu erwähnen ... dort kann man einen Parameter (aktuell leider nur String oder Integer) angeben, welcher dann via Format eingefügt wird ... wollte mir damit etwas das Leben erleichtern, da ich vorher soetwas hatte :shock:
Delphi-Quellcode:
Options.ValueFmt['directory\name' + IntToStr(i)]

franktron 26. Aug 2009 16:03

Re: himXML (gesprochen himix ML)
 
Wie kann man den die Werte dieser XML Datei laden

XML-Code:
<?xml version="1.0"?>
<config>
   <port>35353</port>
  <username>frank</username>
   <password>12345</password>
   <server>lserv</server>
   <db>devtest</db>
   <dbport>3306</dbport>
</config>
Das ist mein Versuch

Delphi-Quellcode:
  XML:=TXMLFile.Create(nil);
  XML.LoadFromFile(FConfigPath+'config.xml');
  With XML.RootNode.Node['config'] do
  Begin
    FDB.Port:=StrToIntDef(Node['port'].Text,35353);
    FDB.Server:=Node['server'].Text;
    FDB.Username:=Node['username'].Text;
    FDB.Password:=Node['password'].Text;
    FDB.Database:=Node['db'].Text;
  End;
da kommt aber nie ein Text raus was mach ich falsch


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:53 Uhr.
Seite 13 von 35   « Erste     3111213 141523     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz