![]() |
Eigenschaftswerte werden nicht gespeicert
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:
Warum werden die Eigenschaften nicht gespeichert? Der Quelltext:
Delphi-Quellcode:
Die Eigenschaften Use...Images geben an, ob die Bilder im jeweiligen ViewStyle angezeigt werden sollen.
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 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) |
Re: Eigenschaftswerte werden nicht gespeicert
Delphi-Quellcode:
Also, wenn du Eigenschaften mit dem Schlüsselwort default versiehst, dann musst du im Konstruktor dafür sorgen,
published
property UseBigImages: Boolean read FUseBigImages write SetUseBigImages default True; property UseSmallImages: Boolean read FUseSmallImages write SetUseSmallImages default True; dass die Properties auch auf diesen Wert gesetzt werden!
Delphi-Quellcode:
constructor TShellIconListView.Create(AOwner: TComponent);
begin inherited; FUseBigImages := True; // <- FUseSmallImages := True; // <- LoadShellIcons; end; |
Re: Eigenschaftswerte werden nicht gespeicert
Zitat:
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. |
Re: Eigenschaftswerte werden nicht gespeicert
Jaa! Daran scheint es gelegen zu haben :party:
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; |
Re: Eigenschaftswerte werden nicht gespeicert
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. ;)
|
Re: Eigenschaftswerte werden nicht gespeicert
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:
Geht's ohne ".Create" oder muss ich die ImagLists vorher doch erzeugen?
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; |
Re: Eigenschaftswerte werden nicht gespeicert
So! Ich hab noch ein wenig an ihr rumgebastelt und sie dann in den OpenSourceteil gepostet.
![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:17 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz