![]() |
abstract error in componente
Liste der Anhänge anzeigen (Anzahl: 1)
Habe hier jede menge abstract Fehler in einer Komponente
Das tritt auf wenn ich diese als obj einlade. Füge ich diese direkt in das Formular ein ist es in ordnung. Zumindest kommt keine Meldung. Nur wenn sie als obj und in das DesignPanel von der Jedi Componente eingefügt wird. Was kann ich da machen ? Bild im Anhang.. und die class
Delphi-Quellcode:
unit cAVeButton;
interface uses Windows,Classes, Graphics, Controls, ExtCtrls, Messages, pngimage; type TcAVeButton = class(TCustomControl) private FUpPic : TPngObject; FDownPic : TPngObject; FOverPic : TPngObject; FBoolTruePic : TPngObject; FBoolFalsePic: TPngObject; FShowBoolPic : Boolean; FFixMode : Boolean; FTouchMode : Boolean; FButtonDown : Boolean; FBoolPicXPos : Integer; FBoolPicYPos : Integer; FLabelXPos : Integer; FLabelYPos : Integer; FAppIndex : Integer; FEntered : Boolean; FShowButton : Boolean; FFunktion : String; FAktion : String; FTimer: TTimer; procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP; procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN; procedure WMMouseEnter( var Message : TWMMouse ); message CM_MOUSEENTER; procedure WMMouseLeave( var Message : TWMMouse ); message CM_MOUSELEAVE; procedure SetDownPic(Value: TPngObject); procedure SetUpPic(Value: TPngObject); procedure SetOverPic(Value: TPngObject); procedure SetBoolTruePic(Value: TPngObject); procedure SetBoolFalsePic(Value: TPngObject); procedure SetText(Value: TCaption); reintroduce; procedure SetTouchMode(Value: Boolean); procedure SetFixMode(Value: Boolean); procedure SetShowButton(Value:Boolean); procedure SetShowBoolPic(Value: Boolean); procedure SetBoolPicXPos(Value: Integer); procedure SetBoolPicYPos(Value: Integer); procedure SetLabelXPos(Value: Integer); procedure SetLabelYPos(Value: Integer); procedure DrawParentBackground(AToDC : HDC); protected procedure Paint; override; procedure TimerEvent(Sender: TObject); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Funktion: String read FFunktion write FFunktion; property Aktion: String read FAktion write FAktion; property Caption write SetText; property UpPicture: TPngObject read FUpPic write SetUpPic; property DownPicture: TPngObject read FDownPic write SetDownPic; property OverPicture: TPngObject read FOverPic write SetOverPic; property BoolTruePicture: TPngObject read FBoolTruePic write SetBoolTruePic; property BoolFalsePicture: TPngObject read FBoolFalsePic write SetBoolFalsePic; property TouchMode: Boolean read FTouchMode write SetTouchMode; property FixMode: Boolean read FFixMode write SetFixMode; property ShowButton: Boolean read FShowButton write SetShowButton; property ShowBoolPic: Boolean read FShowBoolPic write SetShowBoolPic; property BoolPicXPos: Integer read FBoolPicXPos write SetBoolPicXPos; property BoolPicYPos: Integer read FBoolPicYPos write SetBoolPicYPos; property LabelXPos: Integer read FLabelXPos write SetLabelXPos; property LabelYPos: Integer read FLabelYPos write SetLabelYPos; property AppIndex: Integer read FAppIndex write FAppIndex; property Font; property OnMouseDown; property OnMouseUp; property OnClick; end; procedure Register;
Delphi-Quellcode:
gruss Emil
procedure Register;
begin RegisterComponents('cAVe', [TcAVeButton]); end; |
Re: abstract error in componente
Dein Fehler ist schon mal, dass du eine ganz konkrete Klasse TPngObject verwendest.
Richtig wäre, die Klasse TPicture zu verwenden:
Delphi-Quellcode:
Durch die Verwendung von TPicture kann man beliebige Bilder BMP, GIF, JPEG, PNG,... laden.
property UpPicture: TPicture read FUpPic write SetUpPic;
Vorraussetzung zum Laden von PNG-Bildern ist aber, dass die Unit pngimage eingebunden ist. Diese Unit wird aber auch schon zur Entwicklungszeit benötigt!!! Daher musst du dir ein Designtime-Package erstellen, die Unit pgnimage hinzufügen und in der IDE installieren. Dazu muss man wissen, dass Delphi ein Plugin-System für Grafiken hat. Nur wenn die Unit pngimage dieses Plugin-System richtig verwendet, kann die ganze Sache funktionieren. Neue Grafiktypen müssen über TPicture.RegisterFileFormat in der VCL registriert werden. Wenn also RegisterFileFormat im Abschnitt Initialization der Unit pngimage nicht aufgerufen wird, dann läuft etwas falsch. |
Re: abstract error in componente
Zitat:
Delphi-Quellcode:
Wird in PngImage aufgerufen und die Componente ist im system registriert
initialization
{Initialize} ChunkClasses := nil; {crc table has not being computed yet} crc_table_computed := FALSE; {Register the necessary chunks for png} RegisterCommonChunks; {Registers TPNGObject to use with TPicture} {$IFDEF UseDelphi}{$IFDEF RegisterGraphic} TPicture.RegisterFileFormat('PNG', 'Portable Network Graphics', TPNGObject); {$ENDIF}{$ENDIF} finalization {$IFDEF UseDelphi}{$IFDEF RegisterGraphic} TPicture.UnregisterGraphicClass(TPNGObject); {$ENDIF}{$ENDIF} {Free chunk classes} FreeChunkClassList;
Delphi-Quellcode:
Das ändern verursacht aber eine menge neue Fehler
interface
uses Windows,Classes, Graphics, Controls, ExtCtrls, Messages, pngimage; type TcAVeButton = class(TCustomControl) private FUpPic : TPicture; FDownPic : TPicture; FOverPic : TPicture; FBoolTruePic : TPicture; FBoolFalsePic: TPicture; FShowBoolPic : Boolean; FFixMode : Boolean; FTouchMode : Boolean; FButtonDown : Boolean; FBoolPicXPos : Integer; FBoolPicYPos : Integer; FLabelXPos : Integer; FLabelYPos : Integer; FAppIndex : Integer; FEntered : Boolean; FShowButton : Boolean; FFunktion : String; FAktion : String; FTimer: TTimer; [Pascal Error] cAVeButton.pas(148): E2010 Incompatible types: 'TGraphic' and 'TPicture' usw.. Gruss Emil |
Re: abstract error in componente
Zitat:
So würde es jedenfalls ungefähr ausschauen:
Delphi-Quellcode:
Ich weiß jetzt nicht, ob das so alles funktioniert, ist jetzt einfach so aus dem Kopf heraus geschrieben. Ist ja nur zur verdeutlichung
type
TJvInspectorPngImage = class(TJvInspectorStringItem) protected procedure Edit; override; function GetDisplayValue: string; override; procedure SetFlags(const Value: TInspectorItemFlags); override; end; procedure TJvInspectorPngImage.Edit; begin // Hier musst du eine Handling-Routine für ein TPngObject einbauen end; procedure TJvInspectorPngImage.SetFlags(const Value: TInspectorItemFlags); var NewValue: TInspectorItemFlags; begin // Dieser Editortyp hat einen Editor-Button (...) und der Text ist ReadOnly NewValue := Value + [iifEditButton, iifEditFixed]; inherited SetFlags(NewValue); end; function TJvInspectorPngImage.GetDisplayValue: string; begin if TPngImage(Pointer(Data.AsOrdinal)).Empty then result := '(leer)' else result := 'TPngImage'; end; initialization TJvCustomInspectorData.ItemRegister.Add( TJvInspectorTypeInfoRegItem.Create(TJvInspectorPngImage, TypeInfo(TPngObject)) ); |
Re: abstract error in componente
Danke das könnte mir helfen
Nur was ich nicht verstehe habe schon einen Typ von TPicture über den ich PngImage einladen kann.
Delphi-Quellcode:
Habe es jetzt so gemacht wird aber kein bild eingeladen..
TJvCustomInspectorData.ItemRegister.
Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPictureItem , TypeInfo(TPicture)));
Delphi-Quellcode:
TJvInspectorPngImage = class(TJvInspectorClassItem)
protected procedure Edit; override; function GetDisplayValue: string; override; public constructor Create(const AParent: TJvCustomInspectorItem; const AData: TJvCustomInspectorData); override; end;
Delphi-Quellcode:
und bei 'margins' gibt es immer noch einen abstract error.
constructor TJvInspectorPngImage.Create(const AParent: TJvCustomInspectorItem;
const AData: TJvCustomInspectorData); begin inherited Create(AParent, AData); Flags := Flags + [iifEditButton, iifEditFixed]; end; procedure TJvInspectorPngImage.Edit; begin MainForm.dlgPicture.InitialDir := ExtractFilePath(Application.ExeName); if MainForm.dlgPicture.Execute then begin PngImageFile := MainForm.dlgPicture.Filename; tmpPngImage.Picture.LoadFromFile(PngImageFile); SkinManagerInterface.Modified := True; end; // ReInitialisiere Inspector Display Edit Button InitEdit; Inspector.Invalidate; end; function TJvInspectorPngImage.GetDisplayValue: string; begin if TPngObject(Pointer(Data.AsOrdinal)).Empty then Result := 'click to edit' else begin Result := ExtractFileName(MainForm.dlgPicture.Filename); MainForm.JvDesignPanel.Invalidate; end; end; Das image 'tmpPngImage' wird erstellt in ShowSelProperties
Delphi-Quellcode:
Gruss Emil
procedure TCAVEUIObject.ShowSelProperties(Inspector: TJvInspector;
aObj: TObject; Props: array of string; NodeText: string); var i : integer; Category: TJvInspectorCustomCategoryItem; begin Inspector.Root.Clear; Category := TJvInspectorCustomCategoryItem.Create(Inspector.Root, nil); Category.DisplayName := NodeText; Inspector.Root.SortKind := iskNone; for i:=Low(Props) to High(Props) do TJvInspectorPropData.New(Category, aObj, GetPropInfo(aObj, Props[i])); if aObj.classname = 'TImage' then begin tmpImage := TImage(aObj); end else if aObj.classname = 'TcAVeButton' then begin tmpPngImage := TImage(aObj); end; Category.Expanded := True; end; |
Re: abstract error in componente
Delphi-Quellcode:
Du setzt hier den Editor für den Typ TPicture
TJvCustomInspectorData.ItemRegister.
Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPictureItem , TypeInfo(TPicture))); Und hier verwendest du ein cast auf TPngObject:
Delphi-Quellcode:
Diese Zeile müsste lauten:
function TJvInspectorPngImage.GetDisplayValue: string;
begin if TPngObject(Pointer(Data.AsOrdinal)).Empty then <--- da müsste es krachen { ... } end;
Delphi-Quellcode:
So, du kannst ja über den Cast schließlich auf die TPicture-Klasse zugreifen. Warum machst du das dann auch nicht hier:
if TPicture(Pointer(Data.AsOrdinal)).Graphic.Empty then
Delphi-Quellcode:
Dann brauchst du auch das tmpPngImage nicht mehr.
procedure TJvInspectorPngImage.Edit;
begin { ... } if MainForm.dlgPicture.Execute then begin TPicture(Pointer(Data.AsOrdinal)).LoadFromFile(PngImageFile); end; { ... } end; Und mit dem abstakten Fehler: erstell mal ein Editor für die "Margins" - musst ja nichts großes machen - einfach nur mal schauen, ob sich dadurch das Problem löst |
Re: abstract error in componente
Zitat:
habe nur gesagt das ich damit auch Png einladen kann und meine frage war warum muss ich dann ein neues erstellen für PNG.. Für Png habe ich es schon richtig definiert. ;)
Delphi-Quellcode:
so geht es nun .. Danke für die Tips
// TImage
TJvCustomInspectorData.ItemRegister. Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPictureItem , TypeInfo(TPicture))); // Png TJvCustomInspectorData.ItemRegister. Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPngImage, TypeInfo(TPngObject)));
Delphi-Quellcode:
procedure TJvInspectorPngImage.Edit;
begin MainForm.dlgPicture.InitialDir := ExtractFilePath(Application.ExeName); if MainForm.dlgPicture.Execute then begin PngImageFile := MainForm.dlgPicture.Filename; TPngObject(Pointer(Data.AsOrdinal)).LoadFromFile(PngImageFile); SkinManagerInterface.Modified := True; end; // ReInitialisiere Inspector Display Edit Button InitEdit; Inspector.Invalidate; end; |
Re: abstract error in componente
Da bin ich wohl etwas durcheinander gekommen ;-) aber jetzt gehts ja
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:49 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