Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.147 Beiträge
 
Delphi 12 Athens
 

Re: himXML (gesprochen himix ML)

  Alt 1. Aug 2009, 16:00
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

im Zuge einiger anderer Projekte ist diese inzwischen aber gewachsen

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

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;
Miniaturansicht angehängter Grafiken
dialog_187.png  
Angehängte Dateien
Dateityp: dfm optionsselect_112.dfm (2,2 KB, 4x aufgerufen)
Dateityp: pas optionsselect_100.pas (1,7 KB, 4x aufgerufen)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat