AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Eigenschaftswerte werden nicht gespeicert

Ein Thema von F.W. · begonnen am 1. Mai 2005 · letzter Beitrag vom 7. Mai 2005
Antwort Antwort
Benutzerbild von F.W.
F.W.

Registriert seit: 28. Jul 2003
Ort: Zittau
636 Beiträge
 
#1

Eigenschaftswerte werden nicht gespeicert

  Alt 1. Mai 2005, 22:30
Ich habe eine Komponente geschrieben, die von TCustomListBox abgeleitet ist. Der Quellcode folgt unten. Sie ist aber noch nicht ganz fertig, sollte aber eigentlich funktionieren.

Ich habe eigentlich nichts wesentliches geändert, aber seit kurzem werden Eigenschaftswerte nicht mehr gespeichert:
  • wenn ich das Projekt in dem ich die Komponente verwende neu lade sind die Eigenschaftswerte der von mir selbst hinzugefügten Eigenschaften nicht gespeichert
  • wenn ich das Programm starte stehen die Eigenschaftswerte der von mir selbst hinzugefügten Eigenschafteswerte auf Standart
  • wenn ich die Eigenschaftswerte an meine Eigenschaften während der Laufzeit übergebe werden sie "gespeichert" (also wenn ich dann auf sie zugreife, bekomme ich die eingegebenen Werte zurück, aber das kanns ja auch nicht sein, wozu gäbe es denn dann den OI?)

Warum werden die Eigenschaften nicht gespeichert?

Der Quelltext:
Delphi-Quellcode:
unit ShellIconListView;

interface

uses
  SysUtils, Classes, Controls, ComCtrls, CommCtrl, ShellAPI, Windows;

type
  TShellIconListView = class(TCustomListView)
  private
    FileInfoBig, FileInfoSmall: TShFileInfo;
    FBigImages: TImageList;
    FSmallShellImages: TImageList;
    FUseBigImages: Boolean;
    FUseSmallImages: Boolean;
    FBigShellIconsLoaded: Boolean;
    FSmallShellIconsLoaded: Boolean;
    FIndexFileExtension: Integer;
    FIndexTypeAusgabe: Integer;
    procedure SetUseBigImages(const Value: Boolean);
    procedure SetUseSmallImages(const Value: Boolean);
    procedure SetIndexFileExtension(const Value: Integer);
    procedure SetIndexTypeAusgabe(const Value: Integer);
    { Private-Deklarationen }
  protected
    property SmallShellIconsLoaded: Boolean read FSmallShellIconsLoaded default False;
    property BigShellIconsLoaded: Boolean read FBigShellIconsLoaded default False;

    { Protected-Deklarationen }
  public
    constructor Create(AOwner: TComponent); override;

    property SmallShellImages: TImageList read FSmallShellImages;
    property BigImages: TImageList read FBigImages;

    procedure UpdateIcons;
    procedure LoadShellIcons;
    { Public-Deklarationen }
  published
    property UseBigImages: Boolean read FUseBigImages write SetUseBigImages default True;
    property UseSmallImages: Boolean read FUseSmallImages write SetUseSmallImages default True;
    property IndexFileExtension: Integer read FIndexFileExtension write SetIndexFileExtension default -1;//-2 = NotInUse | -1 = Caption | 0.. SubItems
    property IndexTypeAusgabe: Integer read FIndexTypeAusgabe write SetIndexTypeAusgabe default 0;//-2 = NotInUse | -1 = Caption | 0.. SubItems

    property Action;
    property Align;
    property AllocBy;
    property Anchors;
    property BevelEdges;
    property BevelInner;
    property BevelOuter;
    property BevelKind default bkNone;
    property BevelWidth;
    property BiDiMode;
    property BorderStyle;
    property BorderWidth;
    property Checkboxes;
    property Color;
    property Columns;
    property ColumnClick;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property FlatScrollBars;
    property FullDrag;
    property GridLines;
    property HideSelection;
    property HotTrack;
    property HotTrackStyles;
    property HoverTime;
    property IconOptions;
    property Items;
    property MultiSelect;
    property OwnerData;
    property OwnerDraw;
    property ReadOnly default False;
    property RowSelect;
    property ParentBiDiMode;
    property ParentColor default False;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowColumnHeaders;
    property ShowWorkAreas;
    property ShowHint;
    property SortType;
    property StateImages;
    property TabOrder;
    property TabStop default True;
    property ViewStyle;
    property Visible;
    property OnAdvancedCustomDraw;
    property OnAdvancedCustomDrawItem;
    property OnAdvancedCustomDrawSubItem;
    property OnChange;
    property OnChanging;
    property OnClick;
    property OnColumnClick;
    property OnColumnDragged;
    property OnColumnRightClick;
    property OnCompare;
    property OnContextPopup;
    property OnCustomDraw;
    property OnCustomDrawItem;
    property OnCustomDrawSubItem;
    property OnData;
    property OnDataFind;
    property OnDataHint;
    property OnDataStateChange;
    property OnDblClick;
    property OnDeletion;
    property OnDrawItem;
    property OnEdited;
    property OnEditing;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnGetImageIndex;
    property OnGetSubItemImage;
    property OnDragDrop;
    property OnDragOver;
    property OnInfoTip;
    property OnInsert;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnSelectItem;
    property OnStartDock;
    property OnStartDrag;
    { Published-Deklarationen }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Beispiele', [TShellIconListView]);
end;

{ TShellIconListView }

procedure TShellIconListView.LoadShellIcons;
var
 HIb, HIs: HImageList;
begin
 if FUseSmallImages then begin
    ZeroMemory(@FileInfoSmall, SizeOf(FileinfoSmall));
    if not Assigned(FSmallShellImages) then begin
       FSmallShellImages := TImageList.Create(Self);
       FSmallShellImages.ShareImages := True;
       SmallImages := FSmallShellImages;
       FSmallShellIconsLoaded := False;
    end;

    if not FSmallShellIconsLoaded then begin
       HIs := HImageList(ShGetFileInfo('', FILE_ATTRIBUTE_NORMAL, FileInfoSmall, SizeOf(FileInfoSmall), SHGFI_SYSICONINDEX or SHGFI_SMALLICON));
       if (HIs <> 0) then FSmallShellImages.Handle := HIs;
       FSmallShellIconsLoaded := True;
    end;
 end;

 if FUseBigImages then begin
    ZeroMemory(@FileInfoBig, SizeOf(FileInfoBig));
    if not Assigned(FBigImages) then begin
       FBigImages := TImageList.Create(Self);
       FBigImages.ShareImages := True;
       LargeImages := FBigImages;
       FBigShellIconsLoaded := False;
    end;

    if not FBigShellIconsLoaded then begin
       HIb := HImageList(ShGetFileInfo('', FILE_ATTRIBUTE_NORMAL, FileInfoBig, SizeOf(FileInfoBig), SHGFI_SYSICONINDEX or SHGFI_LARGEICON));
       if (HIb <> 0) then FBigImages.Handle := HIb;
       FBigShellIconsLoaded := True;
    end;
 end;
end;

procedure TShellIconListView.SetUseBigImages(const Value: Boolean);
begin
 FUseBigImages := Value;

 if FUseBigImages then LoadShellIcons else BigImages.Free;
end;

procedure TShellIconListView.SetIndexFileExtension(const Value: Integer);
begin
 FIndexFileExtension := Value;
end;

procedure TShellIconListView.SetIndexTypeAusgabe(const Value: Integer);
begin
 FIndexTypeAusgabe := Value;
end;

procedure TShellIconListView.SetUseSmallImages(const Value: Boolean);
begin
 FUseSmallImages := Value;

 if FUseSmallImages then LoadShellIcons else SmallShellImages.Free;
end;

procedure TShellIconListView.UpdateIcons;
var
 I: Integer;
 S: String;
begin
 for I := 0 to Items.Count-1 do begin
     if (FIndexFileExtension > -1) and not (Items[I].SubItems.Count > FIndexFileExtension) then
        Continue;

     if FIndexFileExtension = -1 then S := ExtractFileExt(Items[I].Caption) else
        if FIndexFileExtension > -1 then S := ExtractFileExt(Items[I].SubItems[FIndexFileExtension]) else
           S := '';

     if S <> 'then
        if ViewStyle = vsIcon then begin
           ZeroMemory(@FileInfoBig, SizeOf(FileInfoBig));
           ShGetFileInfo(PChar(S), FILE_ATTRIBUTE_NORMAL, FileInfoBig,sizeof(FileInfoBig),
                         SHGFI_ICON or SHGFI_SYSICONINDEX or SHGFI_LARGEICON or SHGFI_USEFILEATTRIBUTES);

           Items[I].ImageIndex := FileInfoBig.iIcon;
           if FIndexTypeAusgabe = -1 then Items[I].Caption := FileInfoBig.szTypeName else
              if FIndexTypeAusgabe > -1 then begin
                 While Items[I].SubItems.Count <= FIndexTypeAusgabe do
                    Items[I].SubItems.Add('');

                 Items[I].SubItems[FIndexTypeAusgabe] := FileInfoBig.szTypeName;
              end;
        end else begin
           ZeroMemory(@FileInfoSmall, SizeOf(FileInfoSmall));
           ShGetFileInfo(PChar(S), FILE_ATTRIBUTE_NORMAL, FileInfoSmall,sizeof(FileInfoSmall),
                         SHGFI_ICON or SHGFI_SYSICONINDEX or SHGFI_SMALLICON or SHGFI_USEFILEATTRIBUTES);

           Items[I].ImageIndex := FileInfoSmall.iIcon;
           if FIndexTypeAusgabe = -1 then Items[I].Caption := FileInfoSmall.szTypeName else
              if FIndexTypeAusgabe > -1 then begin
                 While Items[I].SubItems.Count <= FIndexTypeAusgabe do
                    Items[I].SubItems.Add('');

                 Items[I].SubItems[FIndexTypeAusgabe] := FileInfoSmall.szTypeName;
              end;
        end;
 end;
end;

constructor TShellIconListView.Create(AOwner: TComponent);
begin
 inherited;

 LoadShellIcons;
end;

end.
Die Eigenschaften Use...Images geben an, ob die Bilder im jeweiligen ViewStyle angezeigt werden sollen.
Die Eigenschaft IndexFileExtension gibt an in welcher Spalte die Komponente nach der Dateierweiterung suchen soll (-2 für aus; -1 für die Caption und 0..? für das jeweilige SubItems)
  Mit Zitat antworten Zitat
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#2

Re: Eigenschaftswerte werden nicht gespeicert

  Alt 2. Mai 2005, 12:33
Delphi-Quellcode:
 published
    property UseBigImages: Boolean read FUseBigImages write SetUseBigImages default True;
    property UseSmallImages: Boolean read FUseSmallImages write SetUseSmallImages default True;
Also, wenn du Eigenschaften mit dem Schlüsselwort default versiehst, dann musst du im Konstruktor dafür sorgen,
dass die Properties auch auf diesen Wert gesetzt werden!
Delphi-Quellcode:
constructor TShellIconListView.Create(AOwner: TComponent);
begin
inherited;
FUseBigImages := True; // <-
FUseSmallImages := True; // <-
LoadShellIcons;
end;
Andreas
  Mit Zitat antworten Zitat
Robert_G
(Gast)

n/a Beiträge
 
#3

Re: Eigenschaftswerte werden nicht gespeicert

  Alt 2. Mai 2005, 12:41
Zitat von shmia:
Delphi-Quellcode:
 published
    property UseBigImages: Boolean read FUseBigImages write SetUseBigImages default True;
    property UseSmallImages: Boolean read FUseSmallImages write SetUseSmallImages default True;
Also, wenn du Eigenschaften mit dem Schlüsselwort default versiehst, dann musst du im Konstruktor dafür sorgen,
dass die Properties auch auf diesen Wert gesetzt werden!
Delphi-Quellcode:
constructor TShellIconListView.Create(AOwner: TComponent);
begin
inherited;
FUseBigImages := True; // <-
FUseSmallImages := True; // <-
LoadShellIcons;
end;
Bei einem Default attribute wird das DFM streaming nur Werte ablegen, die sich vom default Wert unterscheiden.
Hast du "default true", wird ihr Wert NICHT im DFM landen wenn du im OI true einstellst.
Du bist dann also verantwortlich, die Werte im Konstruktor festzulegen.
  Mit Zitat antworten Zitat
Benutzerbild von F.W.
F.W.

Registriert seit: 28. Jul 2003
Ort: Zittau
636 Beiträge
 
#4

Re: Eigenschaftswerte werden nicht gespeicert

  Alt 2. Mai 2005, 16:20
Jaa! Daran scheint es gelegen zu haben

Aber mal noch eine Frage zum Source:
Muss ich die Imagelist mit .Create erzeugen bevor ich ihr das Handle zuweise oder ist die Zeile überflüssig?
Delphi-Quellcode:
//gekürtzt von oben kopiert
 ZeroMemory(@FileInfoSmall, SizeOf(FileinfoSmall));
 FSmallShellImages := TImageList.Create(Self); //MUSS DIESE ZEILE SEIN, WENN DIE IMAGELIST NACHHER SOWIESO DAS HANDLE VON HIs BEKOMMT?
   { ... }
 HIs := HImageList(ShGetFileInfo('', FILE_ATTRIBUTE_NORMAL, FileInfoSmall, SizeOf(FileInfoSmall), SHGFI_SYSICONINDEX or SHGFI_SMALLICON));
 if (HIs <> 0) then FSmallShellImages.Handle := HIs;
  Mit Zitat antworten Zitat
MathiasSimmack
(Gast)

n/a Beiträge
 
#5

Re: Eigenschaftswerte werden nicht gespeicert

  Alt 2. Mai 2005, 16:34
Da du die Symbole aus dem System holst, ist das Erzeugen der Imageliste nicht notwendig. Mögliche Fehlerquellen waren IMHO: das Freigeben der Imageliste, bzw. das Laden ohne das Shared-Attribute. Es sind zwar nur optische Fehler (weil dann bspw. die Symbole im Explorer verschwinden), die sich mit einem Neustart beheben lassen, aber dennoch sieht´s nicht toll aus.
  Mit Zitat antworten Zitat
Benutzerbild von F.W.
F.W.

Registriert seit: 28. Jul 2003
Ort: Zittau
636 Beiträge
 
#6

Re: Eigenschaftswerte werden nicht gespeicert

  Alt 2. Mai 2005, 16:48
Das FREE-Problem habe ich inzwischen korrigiert, die F-Imagelisten werden jetzt nurnoch := NIL gesetzt.

Zum erzeugen:
Sähe dann quasi so aus:
1. Gleichsetzen der Handles
2. ShareImages auf true stellen
3. mit der Small- oder LargeImages-ImageList des ListViews verknüpfen

Funktioniert scheinbar nicht! Ich bekomme eine Zugriffsverletzung beim Übergeben der Handles (if (HIs <> 0) then FSmallShellImages.Handle := HIs)

Aktueller Code:
Delphi-Quellcode:
 if FUseSmallImages then
    if not FSmallShellIconsLoaded then begin
       ZeroMemory(@FileInfo, SizeOf(TSHFileinfo));
       HIs := HImageList(ShGetFileInfo('', FILE_ATTRIBUTE_NORMAL, FileInfo, SizeOf(TSHFileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON));
       if (HIs <> 0) then FSmallShellImages.Handle := HIs;
       FSmallShellImages.ShareImages := True;
       SmallImages := FSmallShellImages;
       FSmallShellIconsLoaded := True;
    end;
Geht's ohne ".Create" oder muss ich die ImagLists vorher doch erzeugen?
  Mit Zitat antworten Zitat
Benutzerbild von F.W.
F.W.

Registriert seit: 28. Jul 2003
Ort: Zittau
636 Beiträge
 
#7

Re: Eigenschaftswerte werden nicht gespeicert

  Alt 7. Mai 2005, 09:23
So! Ich hab noch ein wenig an ihr rumgebastelt und sie dann in den OpenSourceteil gepostet.
HIER könnt ihr sie euch runterladen. Ich würde mich über auch über ein Feedback freuen
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:18 Uhr.
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