Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi abstract error in componente (https://www.delphipraxis.net/120935-abstract-error-componente.html)

EWeiss 19. Sep 2008 02:32


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:
procedure Register;
begin
  RegisterComponents('cAVe', [TcAVeButton]);
end;
gruss Emil

sx2008 19. Sep 2008 06:16

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:
property UpPicture: TPicture read FUpPic write SetUpPic;
Durch die Verwendung von TPicture kann man beliebige Bilder BMP, GIF, JPEG, PNG,... laden.
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.

EWeiss 19. Sep 2008 10:33

Re: abstract error in componente
 
Zitat:

Zitat von sx2008
Dein Fehler ist schon mal, dass du eine ganz konkrete Klasse TPngObject verwendest.
Richtig wäre, die Klasse TPicture zu verwenden:
Delphi-Quellcode:
property UpPicture: TPicture read FUpPic write SetUpPic;
Durch die Verwendung von TPicture kann man beliebige Bilder BMP, GIF, JPEG, PNG,... laden.
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.

Werde das mal testen irgend so etwas habe ich mir schon gedacht.

Delphi-Quellcode:
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;
Wird in PngImage aufgerufen und die Componente ist im system registriert

Delphi-Quellcode:
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;
Das ändern verursacht aber eine menge neue Fehler
[Pascal Error] cAVeButton.pas(148): E2010 Incompatible types: 'TGraphic' and 'TPicture'

usw..

Gruss Emil

littleDave 19. Sep 2008 11:55

Re: abstract error in componente
 
Zitat:

Zitat von sx2008
Dein Fehler ist schon mal, dass du eine ganz konkrete Klasse TPngObject verwendest.
Richtig wäre, die Klasse TPicture zu verwenden:
Delphi-Quellcode:
property UpPicture: TPicture read FUpPic write SetUpPic;
Durch die Verwendung von TPicture kann man beliebige Bilder BMP, GIF, JPEG, PNG,... laden.
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.

Diese Aussage stimmt zwar schon - jedoch nicht in diesem Fall: er benutzt TPngImage zur Laufzeit, somit wird kein DesignTime-Package benötigt. Ich glaube eher, dass es für den JvInspector keinen Editor für das TPngObject gibt. Somit musst du dem JvInspector erstmal einen Editor für TPngObjects bastelt. Wie genau das funktioniert, kannst du im Source vom JvInspector nachschauen - anhand der bereits eingebundenen Objekte.

So würde es jedenfalls ungefähr ausschauen:
Delphi-Quellcode:
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))
  );
Ich weiß jetzt nicht, ob das so alles funktioniert, ist jetzt einfach so aus dem Kopf heraus geschrieben. Ist ja nur zur verdeutlichung

EWeiss 19. Sep 2008 14:03

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:
  TJvCustomInspectorData.ItemRegister.
  Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPictureItem ,
                                           TypeInfo(TPicture)));
Habe es jetzt so gemacht wird aber kein bild eingeladen..


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:
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;
und bei 'margins' gibt es immer noch einen abstract error.
Das image 'tmpPngImage' wird erstellt in ShowSelProperties

Delphi-Quellcode:
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;
Gruss Emil

littleDave 19. Sep 2008 14:22

Re: abstract error in componente
 
Delphi-Quellcode:
  TJvCustomInspectorData.ItemRegister.
  Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPictureItem ,
                                           TypeInfo(TPicture)));
Du setzt hier den Editor für den Typ TPicture
Und hier verwendest du ein cast auf TPngObject:
Delphi-Quellcode:
function TJvInspectorPngImage.GetDisplayValue: string;
begin
  if TPngObject(Pointer(Data.AsOrdinal)).Empty then <--- da müsste es krachen
     { ... }
end;
Diese Zeile müsste lauten:
Delphi-Quellcode:
if TPicture(Pointer(Data.AsOrdinal)).Graphic.Empty then
So, du kannst ja über den Cast schließlich auf die TPicture-Klasse zugreifen. Warum machst du das dann auch nicht hier:
Delphi-Quellcode:
procedure TJvInspectorPngImage.Edit;
begin
  { ... }
  if MainForm.dlgPicture.Execute then
  begin  
    TPicture(Pointer(Data.AsOrdinal)).LoadFromFile(PngImageFile);
  end;
  { ... }
end;
Dann brauchst du auch das tmpPngImage nicht mehr.

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

EWeiss 19. Sep 2008 14:52

Re: abstract error in componente
 
Zitat:

Delphi-Quellcode:
TJvCustomInspectorData.ItemRegister.
  Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPictureItem ,
                                           TypeInfo(TPicture)));
Du setzt hier den Editor für den Typ TPicture
Nein das ist für mein Timage object
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:
  // TImage
  TJvCustomInspectorData.ItemRegister.
  Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPictureItem ,
                                           TypeInfo(TPicture)));
  // Png
  TJvCustomInspectorData.ItemRegister.
  Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorPngImage,
                                         TypeInfo(TPngObject)));
so geht es nun .. Danke für die Tips

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;

littleDave 19. Sep 2008 14:56

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:48 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